Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.

Commit cf32279

Browse files
Merge pull request #2 from madeiramadeirabr/lambda_sqs_scripts
Lambda sqs scripts
2 parents 6720ee6 + e6d29df commit cf32279

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+556
-141
lines changed

.gitignore

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ imagedefinitions.json
5050
config/integration.en
5151
/node_modules/
5252

53-
/examples/lambda_api/vendor/
54-
/examples/lambda_cron/vendor/
55-
/examples/lambda_s3/vendor/
56-
/examples/lambda_sns/vendor/
57-
/examples/lambda_sqs/vendor/
53+
/examples/lambda_api/vendor/*
54+
/examples/lambda_cron/vendor/*
55+
/examples/lambda_s3/vendor/*
56+
/examples/lambda_sns/vendor/*
57+
/examples/lambda_sqs/vendor/*
Lines changed: 50 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,61 @@
11
#!/bin/bash
2-
current_path=$(basename $(pwd))
3-
current_filename=$(basename -- "$0")
4-
current_filename_path=$0
5-
# echo $current_filename_path
6-
current_filename_path="${current_filename_path/$current_filename/''}"
7-
# echo $current_filename_path
8-
current_filename_path="${current_filename_path/scripts\//''}"
9-
# echo $current_filename_path
10-
current_filename_path_basename=$(basename -- "$current_filename_path")
11-
12-
echo "current_path: $current_path"
13-
echo "current_filename: $current_filename"
14-
echo "current_filename_path: $current_filename_path"
15-
echo "current_filename_path_basename: $current_filename_path_basename"
16-
17-
if test -f ${current_filename_path}/scripts/localstack/sqs/create-queue.sh; then
18-
19-
if test -f ${current_filename_path}.projectrc; then
20-
source ${current_filename_path}.projectrc
2+
# -----------------------------------------------------------------------------
3+
# Current file variables
4+
# -----------------------------------------------------------------------------
5+
debug=false
6+
parent_folder="../"
7+
current_path=$(pwd)/
8+
current_path_basename=$(basename $(pwd))
9+
current_file_full_path=$0
10+
# echo $current_filepath
11+
current_file_name=$(basename -- "$0")
12+
# echo $current_filename
13+
if [ $current_file_full_path = $current_file_name ] || [ $current_file_full_path = "./$current_file_name" ]; then
14+
current_file_full_path="./${current_file_full_path}"
15+
current_file_path="./"
16+
else
17+
current_file_path="${current_file_full_path/$current_file_name/''}"
18+
fi
19+
20+
current_file_path_basename=$(basename -- "$current_file_path")
21+
#echo "xxxxx current_file_path_basename $current_file_path_basename"
22+
23+
if [ -z "$current_file_path_basename" ] || [ $current_file_path = "./" ]; then
24+
# echo 'aq'
25+
current_parent_folder="../"
26+
else
27+
# echo 'naq'
28+
current_file_path_basename=$current_file_path_basename/
29+
current_parent_folder="${current_file_path/$current_file_path_basename/''}"
30+
fi
31+
32+
33+
if [ debug ]; then
34+
echo '----------------------------------------'
35+
echo "$0 - Script variables"
36+
echo '----------------------------------------'
37+
echo "current_path: $current_path"
38+
echo "current_path_basename: $current_path_basename"
39+
echo "current_file_full_path: $current_file_full_path"
40+
echo "current_file_name: $current_file_name"
41+
echo "current_file_path: $current_file_path"
42+
echo "current_parent_folder: $current_parent_folder"
43+
echo '----------------------------------------'
44+
fi
45+
46+
if test -f ${current_parent_folder}/scripts/localstack/sqs/create-queue.sh; then
47+
48+
# echo "${current_parent_folder}.projectrc"
49+
if test -f ${current_parent_folder}.projectrc; then
50+
source ${current_parent_folder}.projectrc
2151
fi
2252

2353
if [ -z "$APP_QUEUE" ]; then
2454
echo 'APP_QUEUE not defined'
2555
exit 1
2656
else
2757
echo "Creating the queue: $APP_QUEUE"
28-
${current_filename_path}/scripts/localstack/sqs/create-queue.sh $APP_QUEUE
58+
${current_parent_folder}/scripts/localstack/sqs/create-queue.sh $APP_QUEUE
2959
fi
3060
fi
3161

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"sample": "json"
3+
}

examples/lambda_api/scripts/localstack/sqs/send-message.sh

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,43 @@
1+
# -----------------------------------------------------------------------------
2+
# Current file variables
3+
# -----------------------------------------------------------------------------
4+
debug=true
5+
parent_folder="../"
6+
current_path=$(pwd)/
7+
current_path_basename=$(basename $(pwd))
8+
current_file_full_path=$0
9+
current_file_name=$(basename -- "$0")
10+
if [ $current_file_full_path = $current_file_name ] || [ $current_file_full_path = "./$current_file_name" ]; then
11+
current_file_full_path="./${current_file_full_path}"
12+
current_file_path="./"
13+
else
14+
current_file_path="${current_file_full_path/$current_file_name/''}"
15+
fi
16+
17+
current_file_path_basename=$(basename -- "$current_file_path")
18+
19+
if [ -z "$current_file_path_basename" ] || [ $current_file_path = "./" ]; then
20+
current_parent_folder="../"
21+
else
22+
current_file_path_basename=$current_file_path_basename/
23+
# TODO: está com problema (corrigir)
24+
current_parent_folder="${current_file_path/$current_file_path_basename/''}"
25+
fi
26+
27+
28+
if [ debug ]; then
29+
echo '----------------------------------------'
30+
echo "$0 - Script variables"
31+
echo '----------------------------------------'
32+
echo "current_path: $current_path"
33+
echo "current_path_basename: $current_path_basename"
34+
echo "current_file_full_path: $current_file_full_path"
35+
echo "current_file_name: $current_file_name"
36+
echo "current_file_path: $current_file_path"
37+
echo "current_parent_folder: $current_parent_folder"
38+
echo '----------------------------------------'
39+
fi
40+
141
QUEUE=$1
242
if [ -z "$QUEUE" ]
343
then
@@ -9,9 +49,10 @@ fi
949
MESSAGE=$2
1050
if [ -z "$MESSAGE" ]
1151
then
12-
MESSAGE=$(cat samples/localstack/sqs/sample.json)
52+
MESSAGE=$(cat ${current_file_path}sample.json)
1353
fi
14-
#echo $QUEUE
15-
#exit
54+
55+
# cat ${current_file_path}sample.json
56+
# echo $MESSAGE
1657
echo "aws --endpoint-url=http://localhost:4566 sqs send-message --queue-url $QUEUE --message-body '$MESSAGE'"
1758
aws --endpoint-url=http://localhost:4566 sqs send-message --queue-url $QUEUE --message-body "'$MESSAGE'"

examples/lambda_sqs/.projectrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
PROJECT_NAME=template-serverless-lambda-python-lambda-sqs
22
NETWORK_NAME=service-python
3+
APP_QUEUE=test-queue
4+
APP_LAMBDA_NAME=lambda_sqs
5+
APP_LAMBDA_EVENT_SOURCE=true

examples/lambda_sqs/lambda_app/services/v1/carrier_notifier_service.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from lambda_app.helper import generate_hash
88
from lambda_app.logging import get_logger
99
from lambda_app.repositories.mysql.ocoren_repository import OcorenRepository
10+
from lambda_app.repositories.redis.product_repository import ProductRepository
1011
from lambda_app.vos.ocoren import OcorenVO
1112

1213

@@ -16,6 +17,7 @@ def __init__(self, logger=None, repository=None):
1617
self.logger = logger if logger is not None else get_logger()
1718

1819
self.repository = repository if repository is not None else OcorenRepository()
20+
self.redis_repository = ProductRepository()
1921
self.repository.debug = True
2022

2123
def process(self, sqs_event):
@@ -51,6 +53,10 @@ def process(self, sqs_event):
5153
event_vo = OcorenVO(event)
5254
self.logger.info('event_vo: {}'.format(event_vo.to_dict()))
5355
created = self.repository.create(event_vo)
56+
57+
self.redis_repository.create("event_{}".format(event_hash), str(event_vo.to_dict()))
58+
# self.redis_repository.list(where="*")
59+
5460
if not created:
5561
result = False
5662

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/bin/bash
2+
# -----------------------------------------------------------------------------
3+
# Current file variables
4+
# -----------------------------------------------------------------------------
5+
debug=false
6+
parent_folder="../"
7+
current_path=$(pwd)/
8+
current_path_basename=$(basename $(pwd))
9+
current_file_full_path=$0
10+
# echo $current_filepath
11+
current_file_name=$(basename -- "$0")
12+
# echo $current_filename
13+
if [ $current_file_full_path = $current_file_name ] || [ $current_file_full_path = "./$current_file_name" ]; then
14+
current_file_full_path="./${current_file_full_path}"
15+
current_file_path="./"
16+
else
17+
current_file_path="${current_file_full_path/$current_file_name/''}"
18+
fi
19+
20+
current_file_path_basename=$(basename -- "$current_file_path")
21+
#echo "xxxxx current_file_path_basename $current_file_path_basename"
22+
23+
if [ -z "$current_file_path_basename" ] || [ $current_file_path = "./" ]; then
24+
# echo 'aq'
25+
current_parent_folder="../"
26+
else
27+
# echo 'naq'
28+
current_file_path_basename=$current_file_path_basename/
29+
current_parent_folder="${current_file_path/$current_file_path_basename/''}"
30+
fi
31+
32+
33+
if [ debug ]; then
34+
echo '----------------------------------------'
35+
echo "$0 - Script variables"
36+
echo '----------------------------------------'
37+
echo "current_path: $current_path"
38+
echo "current_path_basename: $current_path_basename"
39+
echo "current_file_full_path: $current_file_full_path"
40+
echo "current_file_name: $current_file_name"
41+
echo "current_file_path: $current_file_path"
42+
echo "current_parent_folder: $current_parent_folder"
43+
echo '----------------------------------------'
44+
fi
45+
46+
if test -f ${current_parent_folder}/scripts/migrations/mysql/migrate.py; then
47+
echo '----------------------------------------'
48+
echo 'Booting database...'
49+
echo '----------------------------------------'
50+
# TODO futuramente usar o Flask migrate ou outra alternativa
51+
echo 'Creating tables...'
52+
python3 ${current_parent_folder}/scripts/migrations/mysql/migrate.py ${current_parent_folder}/tests/datasets/database/structure/mysql/create.table.store.ocorens.sql
53+
python3 ${current_parent_folder}/scripts/migrations/mysql/migrate.py ${current_parent_folder}/tests/datasets/database/structure/mysql/create.table.store.products.sql
54+
55+
read -p "Press enter to continue..."
56+
57+
echo 'Inserting data in the table...'
58+
python3 ${current_parent_folder}/scripts/migrations/mysql/migrate.py ${current_parent_folder}/tests/datasets/database/seeders/mysql/seeder.table.store.ocorens.sql
59+
python3 ${current_parent_folder}/scripts/migrations/mysql/migrate.py ${current_parent_folder}/tests/datasets/database/seeders/mysql/seeder.table.store.products.sql
60+
fi
61+
62+
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/bin/bash
2+
# -----------------------------------------------------------------------------
3+
# Current file variables
4+
# -----------------------------------------------------------------------------
5+
debug=false
6+
parent_folder="../"
7+
current_path=$(pwd)/
8+
current_path_basename=$(basename $(pwd))
9+
current_file_full_path=$0
10+
# echo $current_filepath
11+
current_file_name=$(basename -- "$0")
12+
# echo $current_filename
13+
if [ $current_file_full_path = $current_file_name ] || [ $current_file_full_path = "./$current_file_name" ]; then
14+
current_file_full_path="./${current_file_full_path}"
15+
current_file_path="./"
16+
else
17+
current_file_path="${current_file_full_path/$current_file_name/''}"
18+
fi
19+
20+
current_file_path_basename=$(basename -- "$current_file_path")
21+
#echo "xxxxx current_file_path_basename $current_file_path_basename"
22+
23+
if [ -z "$current_file_path_basename" ] || [ $current_file_path = "./" ]; then
24+
# echo 'aq'
25+
current_parent_folder="../"
26+
else
27+
# echo 'naq'
28+
current_file_path_basename=$current_file_path_basename/
29+
current_parent_folder="${current_file_path/$current_file_path_basename/''}"
30+
fi
31+
32+
33+
if [ debug ]; then
34+
echo '----------------------------------------'
35+
echo "$0 - Script variables"
36+
echo '----------------------------------------'
37+
echo "current_path: $current_path"
38+
echo "current_path_basename: $current_path_basename"
39+
echo "current_file_full_path: $current_file_full_path"
40+
echo "current_file_name: $current_file_name"
41+
echo "current_file_path: $current_file_path"
42+
echo "current_parent_folder: $current_parent_folder"
43+
echo '----------------------------------------'
44+
fi
45+
46+
echo '----------------------------------------'
47+
echo "$0 - Booting lambda"
48+
echo '----------------------------------------'
49+
echo 'Installing dependencies...'
50+
echo "Requirements file: ${current_parent_folder}requirements.txt"
51+
if test -f ${current_parent_folder}requirements.txt; then
52+
python3 -m pip install -r ${current_parent_folder}requirements.txt -t ${current_parent_folder}vendor
53+
# cat ${current_parent_folder}requirements.txt
54+
echo "requirements..."
55+
fi
56+
57+
echo "Requirements file: ${current_parent_folder}requirements-vendor.txt"
58+
if test -f ${current_parent_folder}requirement.s-vendor.txt; then
59+
python3 -m pip install -r ${current_parent_folder}requirements-vendor.txt -t ${current_parent_folder}vendor
60+
# cat ${current_parent_folder}requirements-vendor.txt
61+
echo "requirements vendor..."
62+
fi
63+
64+
read -p "Press enter to continue..."
65+
66+
#echo 'Creating resource dependencies...'
67+
#echo "${current_parent_folder}scripts/localstack/lambda/create-function-from-s3.sh"
68+
69+
if test -f "${current_parent_folder}scripts/localstack/lambda/create-function-from-s3.sh"; then
70+
71+
if test -f ${current_parent_folder}.projectrc; then
72+
source ${current_parent_folder}.projectrc
73+
fi
74+
75+
if [ -z "$APP_LAMBDA_NAME" ]; then
76+
echo 'APP_LAMBDA_NAME not defined'
77+
exit 1
78+
else
79+
echo '----------------------------------------'
80+
echo "$0 - Creating the lambda: $APP_LAMBDA_NAME"
81+
echo '----------------------------------------'
82+
${current_parent_folder}scripts/localstack/lambda/create-function-from-s3.sh $current_filename_path $APP_LAMBDA_NAME
83+
84+
read -p "Press enter to continue..."
85+
86+
if test $APP_LAMBDA_EVENT_SOURCE = true;then
87+
echo '----------------------------------------'
88+
echo "$0 - Creating the event source: $APP_LAMBDA_NAME"
89+
echo '----------------------------------------'
90+
${current_parent_folder}scripts/localstack/lambda/create-event-source-mapping.sh $APP_LAMBDA_NAME $APP_QUEUE
91+
else
92+
echo 'There is no event source for this lambda'
93+
fi
94+
fi
95+
else
96+
echo "File not found: ${current_parent_folder}scripts/localstack/lambda/create-function-from-s3.sh"
97+
fi

0 commit comments

Comments
 (0)