-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add build script for Lambda functions #1595
Open
tinyg210
wants to merge
1
commit into
main
Choose a base branch
from
add_build_lambdas_step_to_quickstart
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+50
−43
Open
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
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,7 +112,14 @@ Another Lambda function lists and provides pre-signed URLs for browser display. | |
The application also handles Lambda failures through SNS and SES email notifications. | ||
|
||
The sample application uses AWS CLI and our `awslocal` wrapper to deploy the application to LocalStack. | ||
You can build and deploy the sample application on LocalStack by running the following command: | ||
Before going further, you need to build your Lambda functions. | ||
You can use the following script that will cover all three of them: | ||
|
||
{{< command >}} | ||
$ deployment/build-lambdas.sh | ||
{{< / command >}} | ||
|
||
You can now deploy the sample application on LocalStack by running the following command: | ||
|
||
{{< command >}} | ||
$ deployment/awslocal/deploy.sh | ||
|
@@ -136,13 +143,13 @@ $ awslocal s3 mb s3://localstack-thumbnails-app-resized | |
|
||
{{< command >}} | ||
$ awslocal ssm put-parameter \ | ||
--name /localstack-thumbnail-app/buckets/images \ | ||
--type "String" \ | ||
--value "localstack-thumbnails-app-images" | ||
--name /localstack-thumbnail-app/buckets/images \ | ||
--type "String" \ | ||
--value "localstack-thumbnails-app-images" | ||
$ awslocal ssm put-parameter \ | ||
--name /localstack-thumbnail-app/buckets/resized \ | ||
--type "String" \ | ||
--value "localstack-thumbnails-app-resized" | ||
--name /localstack-thumbnail-app/buckets/resized \ | ||
--type "String" \ | ||
--value "localstack-thumbnails-app-resized" | ||
{{< / command >}} | ||
|
||
#### Create SNS DLQ Topic for failed lambda invocations | ||
|
@@ -156,45 +163,45 @@ You can use the following command to subscribe an email address to the SNS topic | |
|
||
{{< command >}} | ||
$ awslocal sns subscribe \ | ||
--topic-arn arn:aws:sns:us-east-1:000000000000:failed-resize-topic \ | ||
--protocol email \ | ||
--notification-endpoint [email protected] | ||
--topic-arn arn:aws:sns:us-east-1:000000000000:failed-resize-topic \ | ||
--protocol email \ | ||
--notification-endpoint [email protected] | ||
{{< / command >}} | ||
|
||
#### Create the Presign Lambda | ||
|
||
{{< command >}} | ||
$ (cd lambdas/presign; rm -f lambda.zip; zip lambda.zip handler.py) | ||
$ awslocal lambda create-function \ | ||
--function-name presign \ | ||
--runtime python3.9 \ | ||
--timeout 10 \ | ||
--zip-file fileb://lambdas/presign/lambda.zip \ | ||
--handler handler.handler \ | ||
--role arn:aws:iam::000000000000:role/lambda-role \ | ||
--environment Variables="{STAGE=local}" | ||
--function-name presign \ | ||
--runtime python3.9 \ | ||
--timeout 10 \ | ||
--zip-file fileb://lambdas/presign/lambda.zip \ | ||
--handler handler.handler \ | ||
--role arn:aws:iam::000000000000:role/lambda-role \ | ||
--environment Variables="{STAGE=local}" | ||
$ awslocal lambda wait function-active-v2 --function-name presign | ||
$ awslocal lambda create-function-url-config \ | ||
--function-name presign \ | ||
--auth-type NONE | ||
--function-name presign \ | ||
--auth-type NONE | ||
{{< / command >}} | ||
|
||
#### Create the Image List Lambda | ||
|
||
{{< command >}} | ||
$ (cd lambdas/list; rm -f lambda.zip; zip lambda.zip handler.py) | ||
$ awslocal lambda create-function \ | ||
--function-name list \ | ||
--handler handler.handler \ | ||
--zip-file fileb://lambdas/list/lambda.zip \ | ||
--runtime python3.9 \ | ||
--timeout 10 \ | ||
--role arn:aws:iam::000000000000:role/lambda-role \ | ||
--environment Variables="{STAGE=local}" | ||
--function-name list \ | ||
--handler handler.handler \ | ||
--zip-file fileb://lambdas/list/lambda.zip \ | ||
--runtime python3.9 \ | ||
--timeout 10 \ | ||
--role arn:aws:iam::000000000000:role/lambda-role \ | ||
--environment Variables="{STAGE=local}" | ||
$ awslocal lambda wait function-active-v2 --function-name list | ||
$ awslocal lambda create-function-url-config \ | ||
--function-name list \ | ||
--auth-type NONE | ||
--function-name list \ | ||
--auth-type NONE | ||
{{< / command >}} | ||
|
||
#### Build the Image Resizer Lambda | ||
|
@@ -203,7 +210,7 @@ $ awslocal lambda create-function-url-config \ | |
{{< tab header="macOS" lang="shell" >}} | ||
cd lambdas/resize | ||
rm -rf libs lambda.zip | ||
docker run --platform linux/x86_64 -v "$PWD":/var/task "public.ecr.aws/sam/build-python3.9" /bin/sh -c "pip install -r requirements.txt -t libs; exit" | ||
docker run --platform linux/x86*64 -v "$PWD":/var/task "public.ecr.aws/sam/build-python3.9" /bin/sh -c "pip install -r requirements.txt -t libs; exit" | ||
cd libs && zip -r ../lambda.zip . && cd .. | ||
zip lambda.zip handler.py | ||
rm -rf libs | ||
|
@@ -226,7 +233,7 @@ mkdir package | |
pip install -r requirements.txt -t package | ||
zip lambda.zip handler.py | ||
cd package | ||
zip -r ../lambda.zip*; | ||
zip -r ../lambda.zip\_; | ||
cd ../.. | ||
{{< /tab >}} | ||
{{< /tabpane >}} | ||
|
@@ -235,27 +242,27 @@ cd ../.. | |
|
||
{{< command >}} | ||
$ awslocal lambda create-function \ | ||
--function-name resize \ | ||
--runtime python3.9 \ | ||
--timeout 10 \ | ||
--zip-file fileb://lambdas/resize/lambda.zip \ | ||
--handler handler.handler \ | ||
--dead-letter-config TargetArn=arn:aws:sns:us-east-1:000000000000:failed-resize-topic \ | ||
--role arn:aws:iam::000000000000:role/lambda-role \ | ||
--environment Variables="{STAGE=local}" | ||
--function-name resize \ | ||
--runtime python3.9 \ | ||
--timeout 10 \ | ||
--zip-file fileb://lambdas/resize/lambda.zip \ | ||
--handler handler.handler \ | ||
--dead-letter-config TargetArn=arn:aws:sns:us-east-1:000000000000:failed-resize-topic \ | ||
--role arn:aws:iam::000000000000:role/lambda-role \ | ||
--environment Variables="{STAGE=local}" | ||
$ awslocal lambda wait function-active-v2 --function-name resize | ||
$ awslocal lambda put-function-event-invoke-config \ | ||
--function-name resize \ | ||
--maximum-event-age-in-seconds 3600 \ | ||
--maximum-retry-attempts 0 | ||
--function-name resize \ | ||
--maximum-event-age-in-seconds 3600 \ | ||
--maximum-retry-attempts 0 | ||
{{< / command >}} | ||
|
||
#### Connect S3 bucket to Resizer Lambda | ||
|
||
{{< command >}} | ||
$ awslocal s3api put-bucket-notification-configuration \ | ||
--bucket localstack-thumbnails-app-images \ | ||
--notification-configuration "{\"LambdaFunctionConfigurations\": [{\"LambdaFunctionArn\": \"$(awslocal lambda get-function --function-name resize --output json | jq -r .Configuration.FunctionArn)\", \"Events\": [\"s3:ObjectCreated:*\"]}]}" | ||
--bucket localstack-thumbnails-app-images \ | ||
--notification-configuration "{\"LambdaFunctionConfigurations\": [{\"LambdaFunctionArn\": \"$(awslocal lambda get-function --function-name resize --output json | jq -r .Configuration.FunctionArn)\", \"Events\": [\"s3:ObjectCreated:*\"]}]}" | ||
{{< / command >}} | ||
|
||
#### Create the S3 static website | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor suggestion: Would it make sense to upgrade to python3.12 because 3.9 might get deprecated next year (it's the latest non-deprecation Python version) https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html
Thank you @tinyg210 for tackling the missing build instructions, that's indeed a common issue 👍