Skip to content

Commit

Permalink
add lambdas build script for quickstart guide
Browse files Browse the repository at this point in the history
  • Loading branch information
tinyg210 committed Dec 14, 2024
1 parent 81af892 commit 1430c02
Showing 1 changed file with 50 additions and 43 deletions.
93 changes: 50 additions & 43 deletions content/en/getting-started/quickstart/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 >}}
Expand All @@ -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
Expand Down

0 comments on commit 1430c02

Please sign in to comment.