Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ imagedefinitions.json
config/integration.en
/node_modules/

/examples/lambda_api/vendor/
/examples/lambda_cron/vendor/
/examples/lambda_s3/vendor/
/examples/lambda_sns/vendor/
/examples/lambda_sqs/vendor/
/examples/lambda_api/vendor/*
/examples/lambda_cron/vendor/*
/examples/lambda_s3/vendor/*
/examples/lambda_sns/vendor/*
/examples/lambda_sqs/vendor/*
70 changes: 50 additions & 20 deletions examples/lambda_api/scripts/boot-queues.sh
Original file line number Diff line number Diff line change
@@ -1,31 +1,61 @@
#!/bin/bash
current_path=$(basename $(pwd))
current_filename=$(basename -- "$0")
current_filename_path=$0
# echo $current_filename_path
current_filename_path="${current_filename_path/$current_filename/''}"
# echo $current_filename_path
current_filename_path="${current_filename_path/scripts\//''}"
# echo $current_filename_path
current_filename_path_basename=$(basename -- "$current_filename_path")

echo "current_path: $current_path"
echo "current_filename: $current_filename"
echo "current_filename_path: $current_filename_path"
echo "current_filename_path_basename: $current_filename_path_basename"

if test -f ${current_filename_path}/scripts/localstack/sqs/create-queue.sh; then

if test -f ${current_filename_path}.projectrc; then
source ${current_filename_path}.projectrc
# -----------------------------------------------------------------------------
# Current file variables
# -----------------------------------------------------------------------------
debug=false
parent_folder="../"
current_path=$(pwd)/
current_path_basename=$(basename $(pwd))
current_file_full_path=$0
# echo $current_filepath
current_file_name=$(basename -- "$0")
# echo $current_filename
if [ $current_file_full_path = $current_file_name ] || [ $current_file_full_path = "./$current_file_name" ]; then
current_file_full_path="./${current_file_full_path}"
current_file_path="./"
else
current_file_path="${current_file_full_path/$current_file_name/''}"
fi

current_file_path_basename=$(basename -- "$current_file_path")
#echo "xxxxx current_file_path_basename $current_file_path_basename"

if [ -z "$current_file_path_basename" ] || [ $current_file_path = "./" ]; then
# echo 'aq'
current_parent_folder="../"
else
# echo 'naq'
current_file_path_basename=$current_file_path_basename/
current_parent_folder="${current_file_path/$current_file_path_basename/''}"
fi


if [ debug ]; then
echo '----------------------------------------'
echo "$0 - Script variables"
echo '----------------------------------------'
echo "current_path: $current_path"
echo "current_path_basename: $current_path_basename"
echo "current_file_full_path: $current_file_full_path"
echo "current_file_name: $current_file_name"
echo "current_file_path: $current_file_path"
echo "current_parent_folder: $current_parent_folder"
echo '----------------------------------------'
fi

if test -f ${current_parent_folder}/scripts/localstack/sqs/create-queue.sh; then

# echo "${current_parent_folder}.projectrc"
if test -f ${current_parent_folder}.projectrc; then
source ${current_parent_folder}.projectrc
fi

if [ -z "$APP_QUEUE" ]; then
echo 'APP_QUEUE not defined'
exit 1
else
echo "Creating the queue: $APP_QUEUE"
${current_filename_path}/scripts/localstack/sqs/create-queue.sh $APP_QUEUE
${current_parent_folder}/scripts/localstack/sqs/create-queue.sh $APP_QUEUE
fi
fi

3 changes: 3 additions & 0 deletions examples/lambda_api/scripts/localstack/sqs/sample.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"sample": "json"
}
47 changes: 44 additions & 3 deletions examples/lambda_api/scripts/localstack/sqs/send-message.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,43 @@
# -----------------------------------------------------------------------------
# Current file variables
# -----------------------------------------------------------------------------
debug=true
parent_folder="../"
current_path=$(pwd)/
current_path_basename=$(basename $(pwd))
current_file_full_path=$0
current_file_name=$(basename -- "$0")
if [ $current_file_full_path = $current_file_name ] || [ $current_file_full_path = "./$current_file_name" ]; then
current_file_full_path="./${current_file_full_path}"
current_file_path="./"
else
current_file_path="${current_file_full_path/$current_file_name/''}"
fi

current_file_path_basename=$(basename -- "$current_file_path")

if [ -z "$current_file_path_basename" ] || [ $current_file_path = "./" ]; then
current_parent_folder="../"
else
current_file_path_basename=$current_file_path_basename/
# TODO: está com problema (corrigir)
current_parent_folder="${current_file_path/$current_file_path_basename/''}"
fi


if [ debug ]; then
echo '----------------------------------------'
echo "$0 - Script variables"
echo '----------------------------------------'
echo "current_path: $current_path"
echo "current_path_basename: $current_path_basename"
echo "current_file_full_path: $current_file_full_path"
echo "current_file_name: $current_file_name"
echo "current_file_path: $current_file_path"
echo "current_parent_folder: $current_parent_folder"
echo '----------------------------------------'
fi

QUEUE=$1
if [ -z "$QUEUE" ]
then
Expand All @@ -9,9 +49,10 @@ fi
MESSAGE=$2
if [ -z "$MESSAGE" ]
then
MESSAGE=$(cat samples/localstack/sqs/sample.json)
MESSAGE=$(cat ${current_file_path}sample.json)
fi
#echo $QUEUE
#exit

# cat ${current_file_path}sample.json
# echo $MESSAGE
echo "aws --endpoint-url=http://localhost:4566 sqs send-message --queue-url $QUEUE --message-body '$MESSAGE'"
aws --endpoint-url=http://localhost:4566 sqs send-message --queue-url $QUEUE --message-body "'$MESSAGE'"
3 changes: 3 additions & 0 deletions examples/lambda_sqs/.projectrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
PROJECT_NAME=template-serverless-lambda-python-lambda-sqs
NETWORK_NAME=service-python
APP_QUEUE=test-queue
APP_LAMBDA_NAME=lambda_sqs
APP_LAMBDA_EVENT_SOURCE=true
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from lambda_app.helper import generate_hash
from lambda_app.logging import get_logger
from lambda_app.repositories.mysql.ocoren_repository import OcorenRepository
from lambda_app.repositories.redis.product_repository import ProductRepository
from lambda_app.vos.ocoren import OcorenVO


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

self.repository = repository if repository is not None else OcorenRepository()
self.redis_repository = ProductRepository()
self.repository.debug = True

def process(self, sqs_event):
Expand Down Expand Up @@ -51,6 +53,10 @@ def process(self, sqs_event):
event_vo = OcorenVO(event)
self.logger.info('event_vo: {}'.format(event_vo.to_dict()))
created = self.repository.create(event_vo)

self.redis_repository.create("event_{}".format(event_hash), str(event_vo.to_dict()))
# self.redis_repository.list(where="*")

if not created:
result = False

Expand Down
62 changes: 62 additions & 0 deletions examples/lambda_sqs/scripts/boot-db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/bash
# -----------------------------------------------------------------------------
# Current file variables
# -----------------------------------------------------------------------------
debug=false
parent_folder="../"
current_path=$(pwd)/
current_path_basename=$(basename $(pwd))
current_file_full_path=$0
# echo $current_filepath
current_file_name=$(basename -- "$0")
# echo $current_filename
if [ $current_file_full_path = $current_file_name ] || [ $current_file_full_path = "./$current_file_name" ]; then
current_file_full_path="./${current_file_full_path}"
current_file_path="./"
else
current_file_path="${current_file_full_path/$current_file_name/''}"
fi

current_file_path_basename=$(basename -- "$current_file_path")
#echo "xxxxx current_file_path_basename $current_file_path_basename"

if [ -z "$current_file_path_basename" ] || [ $current_file_path = "./" ]; then
# echo 'aq'
current_parent_folder="../"
else
# echo 'naq'
current_file_path_basename=$current_file_path_basename/
current_parent_folder="${current_file_path/$current_file_path_basename/''}"
fi


if [ debug ]; then
echo '----------------------------------------'
echo "$0 - Script variables"
echo '----------------------------------------'
echo "current_path: $current_path"
echo "current_path_basename: $current_path_basename"
echo "current_file_full_path: $current_file_full_path"
echo "current_file_name: $current_file_name"
echo "current_file_path: $current_file_path"
echo "current_parent_folder: $current_parent_folder"
echo '----------------------------------------'
fi

if test -f ${current_parent_folder}/scripts/migrations/mysql/migrate.py; then
echo '----------------------------------------'
echo 'Booting database...'
echo '----------------------------------------'
# TODO futuramente usar o Flask migrate ou outra alternativa
echo 'Creating tables...'
python3 ${current_parent_folder}/scripts/migrations/mysql/migrate.py ${current_parent_folder}/tests/datasets/database/structure/mysql/create.table.store.ocorens.sql
python3 ${current_parent_folder}/scripts/migrations/mysql/migrate.py ${current_parent_folder}/tests/datasets/database/structure/mysql/create.table.store.products.sql

read -p "Press enter to continue..."

echo 'Inserting data in the table...'
python3 ${current_parent_folder}/scripts/migrations/mysql/migrate.py ${current_parent_folder}/tests/datasets/database/seeders/mysql/seeder.table.store.ocorens.sql
python3 ${current_parent_folder}/scripts/migrations/mysql/migrate.py ${current_parent_folder}/tests/datasets/database/seeders/mysql/seeder.table.store.products.sql
fi


97 changes: 97 additions & 0 deletions examples/lambda_sqs/scripts/boot-lambda.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#!/bin/bash
# -----------------------------------------------------------------------------
# Current file variables
# -----------------------------------------------------------------------------
debug=false
parent_folder="../"
current_path=$(pwd)/
current_path_basename=$(basename $(pwd))
current_file_full_path=$0
# echo $current_filepath
current_file_name=$(basename -- "$0")
# echo $current_filename
if [ $current_file_full_path = $current_file_name ] || [ $current_file_full_path = "./$current_file_name" ]; then
current_file_full_path="./${current_file_full_path}"
current_file_path="./"
else
current_file_path="${current_file_full_path/$current_file_name/''}"
fi

current_file_path_basename=$(basename -- "$current_file_path")
#echo "xxxxx current_file_path_basename $current_file_path_basename"

if [ -z "$current_file_path_basename" ] || [ $current_file_path = "./" ]; then
# echo 'aq'
current_parent_folder="../"
else
# echo 'naq'
current_file_path_basename=$current_file_path_basename/
current_parent_folder="${current_file_path/$current_file_path_basename/''}"
fi


if [ debug ]; then
echo '----------------------------------------'
echo "$0 - Script variables"
echo '----------------------------------------'
echo "current_path: $current_path"
echo "current_path_basename: $current_path_basename"
echo "current_file_full_path: $current_file_full_path"
echo "current_file_name: $current_file_name"
echo "current_file_path: $current_file_path"
echo "current_parent_folder: $current_parent_folder"
echo '----------------------------------------'
fi

echo '----------------------------------------'
echo "$0 - Booting lambda"
echo '----------------------------------------'
echo 'Installing dependencies...'
echo "Requirements file: ${current_parent_folder}requirements.txt"
if test -f ${current_parent_folder}requirements.txt; then
python3 -m pip install -r ${current_parent_folder}requirements.txt -t ${current_parent_folder}vendor
# cat ${current_parent_folder}requirements.txt
echo "requirements..."
fi

echo "Requirements file: ${current_parent_folder}requirements-vendor.txt"
if test -f ${current_parent_folder}requirement.s-vendor.txt; then
python3 -m pip install -r ${current_parent_folder}requirements-vendor.txt -t ${current_parent_folder}vendor
# cat ${current_parent_folder}requirements-vendor.txt
echo "requirements vendor..."
fi

read -p "Press enter to continue..."

#echo 'Creating resource dependencies...'
#echo "${current_parent_folder}scripts/localstack/lambda/create-function-from-s3.sh"

if test -f "${current_parent_folder}scripts/localstack/lambda/create-function-from-s3.sh"; then

if test -f ${current_parent_folder}.projectrc; then
source ${current_parent_folder}.projectrc
fi

if [ -z "$APP_LAMBDA_NAME" ]; then
echo 'APP_LAMBDA_NAME not defined'
exit 1
else
echo '----------------------------------------'
echo "$0 - Creating the lambda: $APP_LAMBDA_NAME"
echo '----------------------------------------'
${current_parent_folder}scripts/localstack/lambda/create-function-from-s3.sh $current_filename_path $APP_LAMBDA_NAME

read -p "Press enter to continue..."

if test $APP_LAMBDA_EVENT_SOURCE = true;then
echo '----------------------------------------'
echo "$0 - Creating the event source: $APP_LAMBDA_NAME"
echo '----------------------------------------'
${current_parent_folder}scripts/localstack/lambda/create-event-source-mapping.sh $APP_LAMBDA_NAME $APP_QUEUE
else
echo 'There is no event source for this lambda'
fi
fi
else
echo "File not found: ${current_parent_folder}scripts/localstack/lambda/create-function-from-s3.sh"
fi
Loading