Skip to content
This repository was archived by the owner on Aug 7, 2025. It is now read-only.

Commit f6d9bd9

Browse files
authored
Add build script for Lambda functions (#1595)
1 parent 4b19e3f commit f6d9bd9

File tree

1 file changed

+50
-43
lines changed
  • content/en/getting-started/quickstart

1 file changed

+50
-43
lines changed

content/en/getting-started/quickstart/index.md

Lines changed: 50 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,14 @@ Another Lambda function lists and provides pre-signed URLs for browser display.
112112
The application also handles Lambda failures through SNS and SES email notifications.
113113

114114
The sample application uses AWS CLI and our `awslocal` wrapper to deploy the application to LocalStack.
115-
You can build and deploy the sample application on LocalStack by running the following command:
115+
Before going further, you need to build your Lambda functions.
116+
You can use the following script that will cover all three of them:
117+
118+
{{< command >}}
119+
$ deployment/build-lambdas.sh
120+
{{< / command >}}
121+
122+
You can now deploy the sample application on LocalStack by running the following command:
116123

117124
{{< command >}}
118125
$ deployment/awslocal/deploy.sh
@@ -136,13 +143,13 @@ $ awslocal s3 mb s3://localstack-thumbnails-app-resized
136143

137144
{{< command >}}
138145
$ awslocal ssm put-parameter \
139-
--name /localstack-thumbnail-app/buckets/images \
140-
--type "String" \
141-
--value "localstack-thumbnails-app-images"
146+
--name /localstack-thumbnail-app/buckets/images \
147+
--type "String" \
148+
--value "localstack-thumbnails-app-images"
142149
$ awslocal ssm put-parameter \
143-
--name /localstack-thumbnail-app/buckets/resized \
144-
--type "String" \
145-
--value "localstack-thumbnails-app-resized"
150+
--name /localstack-thumbnail-app/buckets/resized \
151+
--type "String" \
152+
--value "localstack-thumbnails-app-resized"
146153
{{< / command >}}
147154

148155
#### 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
156163

157164
{{< command >}}
158165
$ awslocal sns subscribe \
159-
--topic-arn arn:aws:sns:us-east-1:000000000000:failed-resize-topic \
160-
--protocol email \
161-
--notification-endpoint my-email@example.com
166+
--topic-arn arn:aws:sns:us-east-1:000000000000:failed-resize-topic \
167+
--protocol email \
168+
--notification-endpoint my-email@example.com
162169
{{< / command >}}
163170

164171
#### Create the Presign Lambda
165172

166173
{{< command >}}
167174
$ (cd lambdas/presign; rm -f lambda.zip; zip lambda.zip handler.py)
168175
$ awslocal lambda create-function \
169-
--function-name presign \
170-
--runtime python3.9 \
171-
--timeout 10 \
172-
--zip-file fileb://lambdas/presign/lambda.zip \
173-
--handler handler.handler \
174-
--role arn:aws:iam::000000000000:role/lambda-role \
175-
--environment Variables="{STAGE=local}"
176+
--function-name presign \
177+
--runtime python3.9 \
178+
--timeout 10 \
179+
--zip-file fileb://lambdas/presign/lambda.zip \
180+
--handler handler.handler \
181+
--role arn:aws:iam::000000000000:role/lambda-role \
182+
--environment Variables="{STAGE=local}"
176183
$ awslocal lambda wait function-active-v2 --function-name presign
177184
$ awslocal lambda create-function-url-config \
178-
--function-name presign \
179-
--auth-type NONE
185+
--function-name presign \
186+
--auth-type NONE
180187
{{< / command >}}
181188

182189
#### Create the Image List Lambda
183190

184191
{{< command >}}
185192
$ (cd lambdas/list; rm -f lambda.zip; zip lambda.zip handler.py)
186193
$ awslocal lambda create-function \
187-
--function-name list \
188-
--handler handler.handler \
189-
--zip-file fileb://lambdas/list/lambda.zip \
190-
--runtime python3.9 \
191-
--timeout 10 \
192-
--role arn:aws:iam::000000000000:role/lambda-role \
193-
--environment Variables="{STAGE=local}"
194+
--function-name list \
195+
--handler handler.handler \
196+
--zip-file fileb://lambdas/list/lambda.zip \
197+
--runtime python3.9 \
198+
--timeout 10 \
199+
--role arn:aws:iam::000000000000:role/lambda-role \
200+
--environment Variables="{STAGE=local}"
194201
$ awslocal lambda wait function-active-v2 --function-name list
195202
$ awslocal lambda create-function-url-config \
196-
--function-name list \
197-
--auth-type NONE
203+
--function-name list \
204+
--auth-type NONE
198205
{{< / command >}}
199206

200207
#### Build the Image Resizer Lambda
@@ -203,7 +210,7 @@ $ awslocal lambda create-function-url-config \
203210
{{< tab header="macOS" lang="shell" >}}
204211
cd lambdas/resize
205212
rm -rf libs lambda.zip
206-
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"
213+
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"
207214
cd libs && zip -r ../lambda.zip . && cd ..
208215
zip lambda.zip handler.py
209216
rm -rf libs
@@ -226,7 +233,7 @@ mkdir package
226233
pip install -r requirements.txt -t package
227234
zip lambda.zip handler.py
228235
cd package
229-
zip -r ../lambda.zip*;
236+
zip -r ../lambda.zip\_;
230237
cd ../..
231238
{{< /tab >}}
232239
{{< /tabpane >}}
@@ -235,27 +242,27 @@ cd ../..
235242

236243
{{< command >}}
237244
$ awslocal lambda create-function \
238-
--function-name resize \
239-
--runtime python3.9 \
240-
--timeout 10 \
241-
--zip-file fileb://lambdas/resize/lambda.zip \
242-
--handler handler.handler \
243-
--dead-letter-config TargetArn=arn:aws:sns:us-east-1:000000000000:failed-resize-topic \
244-
--role arn:aws:iam::000000000000:role/lambda-role \
245-
--environment Variables="{STAGE=local}"
245+
--function-name resize \
246+
--runtime python3.9 \
247+
--timeout 10 \
248+
--zip-file fileb://lambdas/resize/lambda.zip \
249+
--handler handler.handler \
250+
--dead-letter-config TargetArn=arn:aws:sns:us-east-1:000000000000:failed-resize-topic \
251+
--role arn:aws:iam::000000000000:role/lambda-role \
252+
--environment Variables="{STAGE=local}"
246253
$ awslocal lambda wait function-active-v2 --function-name resize
247254
$ awslocal lambda put-function-event-invoke-config \
248-
--function-name resize \
249-
--maximum-event-age-in-seconds 3600 \
250-
--maximum-retry-attempts 0
255+
--function-name resize \
256+
--maximum-event-age-in-seconds 3600 \
257+
--maximum-retry-attempts 0
251258
{{< / command >}}
252259

253260
#### Connect S3 bucket to Resizer Lambda
254261

255262
{{< command >}}
256263
$ awslocal s3api put-bucket-notification-configuration \
257-
--bucket localstack-thumbnails-app-images \
258-
--notification-configuration "{\"LambdaFunctionConfigurations\": [{\"LambdaFunctionArn\": \"$(awslocal lambda get-function --function-name resize --output json | jq -r .Configuration.FunctionArn)\", \"Events\": [\"s3:ObjectCreated:*\"]}]}"
264+
--bucket localstack-thumbnails-app-images \
265+
--notification-configuration "{\"LambdaFunctionConfigurations\": [{\"LambdaFunctionArn\": \"$(awslocal lambda get-function --function-name resize --output json | jq -r .Configuration.FunctionArn)\", \"Events\": [\"s3:ObjectCreated:*\"]}]}"
259266
{{< / command >}}
260267

261268
#### Create the S3 static website

0 commit comments

Comments
 (0)