1
1
# Serverless image resizer
2
2
3
- [ ![ LocalStack Pods Launchpad] ( https://localstack.cloud/gh/launch-pod-badge.svg )] ( https://app.localstack.cloud/launchpad?url=https://github.com/thrau/serverless-image-resizer/releases/download/v0.1.0/serverless-image-resizer-cloudpod-v0.1.0.zip )
4
-
5
-
6
- A serverless application that demos several AWS functionalities on LocalStack:
7
- * S3
3
+ [ ![ LocalStack Pods Launchpad] ( https://localstack.cloud/gh/launch-pod-badge.svg )] ( https://app.localstack.cloud/launchpad?url=https://github.com/thrau/serverless-image-resizer/releases/download/v1.0.0/serverless-image-resizer-cloudpod-v1.0.0.zip )
4
+
5
+ | Key | Value |
6
+ |--------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
7
+ | Environment | <img src="https://img.shields.io/badge/LocalStack-deploys-4D29B4.svg?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAKgAAACoABZrFArwAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAALbSURBVHic7ZpNaxNRFIafczNTGIq0G2M7pXWRlRv3Lusf8AMFEQT3guDWhX9BcC/uFAr1B4igLgSF4EYDtsuQ3M5GYrTaj3Tmui2SpMnM3PlK3m1uzjnPw8xw50MoaNrttl+r1e4CNRv1jTG/+v3+c8dG8TSilHoAPLZVX0RYWlraUbYaJI2IuLZ7KKUWCisgq8wF5D1A3rF+EQyCYPHo6Ghh3BrP8wb1en3f9izDYlVAp9O5EkXRB8dxxl7QBoNBpLW+7fv+a5vzDIvVU0BELhpjJrmaK2NMw+YsIxunUaTZbLrdbveZ1vpmGvWyTOJToNlsuqurq1vAdWPMeSDzwzhJEh0Bp+FTmifzxBZQBXiIKaAq8BBDQJXgYUoBVYOHKQRUER4mFFBVeJhAQJXh4QwBVYeHMQJmAR5GCJgVeBgiYJbg4T8BswYPp+4GW63WwvLy8hZwLcd5TudvBj3+OFBIeA4PD596nvc1iiIrD21qtdr+ysrKR8cY42itCwUP0Gg0+sC27T5qb2/vMunB/0ipTmZxfN//orW+BCwmrGV6vd63BP9P2j9WxGbxbrd7B3g14fLfwFsROUlzBmNM33XdR6Meuxfp5eg54IYxJvXCx8fHL4F3w36blTdDI4/0WREwMnMBeQ+Qd+YC8h4g78wF5D1A3rEqwBiT6q4ubpRSI+ewuhP0PO/NwcHBExHJZZ8PICI/e73ep7z6zzNPwWP1djhuOp3OfRG5kLROFEXv19fXP49bU6TbYQDa7XZDRF6kUUtEtoFb49YUbh/gOM7YbwqnyG4URQ/PWlQ4ASllNwzDzY2NDX3WwioKmBgeqidgKnioloCp4aE6AmLBQzUExIaH8gtIBA/lFrCTFB7KK2AnDMOrSeGhnAJSg4fyCUgVHsolIHV4KI8AK/BQDgHW4KH4AqzCQwEfiIRheKKUAvjuuu7m2tpakPdMmcYYI1rre0EQ1LPo9w82qyNziMdZ3AAAAABJRU5ErkJggg=="> |
8
+ | Services | S3, SSM, Lambda, SNS, SES |
9
+ | Integrations | AWS SDK, AWS CLI, GitHub actions, pytest |
10
+ | Categories | Serverless, S3 notifications, S3 website, Lambda function URLs, LocalStack developer endpoints, JavaScript, Python | |
11
+ | Level | Intermediate |
12
+
13
+ ## Introduction
14
+
15
+ This is an app to resize images uploaded to S3 in a serverless way.
16
+ A simple web fronted using HTML and JavaScript provides a way for users to upload images that are resized and listed.
17
+ We use a Lambda to generate S3 pre-signed URLs so the upload form can upload directly to S3 rather than going through the Lambda.
18
+ S3 bucket notifications are used to trigger a Python Lambda that runs image resizing.
19
+ Another Lambda is used to list all uploaded and resized images, and provide pre-signed URLs for the browser to display them.
20
+ We also demonstrate how Lambda failures can submit to SNS, which can then trigger an SES email.
21
+ Using the LocalStack internal ` /_localstack/aws/ses ` endpoint, we can run end-to-end integration tests to verify that emails have been sent correctly.
22
+
23
+ Here's a short summary of AWS service features we use:
8
24
* S3 bucket notifications to trigger a Lambda
9
25
* S3 pre-signed POST
10
26
* S3 website
11
- * SSM
12
- * Lambda
13
27
* Lambda function URLs
14
28
* Lambda SNS on failure destination
15
29
* SNS to SES Subscriptions
16
30
* SES LocalStack testing endpoint
17
31
18
- Moreover, the repo includes a GitHub actions workflow to demonstrate how to run end-to-end tests of your AWS apps using LocalStack in CI.
19
-
20
- Here's the app in action:
21
-
32
+ Here's the web application in action:
22
33
23
34
https://user-images.githubusercontent.com/3996682/229314248-86122e9e-0150-4292-b889-401e6fb8f398.mp4
24
35
36
+ Moreover, the repo includes a GitHub actions workflow to demonstrate how to run end-to-end tests of your AWS apps using LocalStack in CI.
37
+ The GitHub workflow runs a set of integration tests using pytest.
25
38
26
- ## Overview
39
+ ## Architecture overview
27
40
28
41
![ Screenshot at 2023-04-02 01-32-56] ( https://user-images.githubusercontent.com/3996682/229322761-92f52eec-5bfb-412a-a3cb-8af4ee1fed24.png )
29
42
@@ -33,6 +46,7 @@ https://user-images.githubusercontent.com/3996682/229314248-86122e9e-0150-4292-b
33
46
34
47
Make sure you use the same version as the Python Lambdas to make Pillow work.
35
48
If you use pyenv, then first install and activate Python 3.9:
49
+
36
50
``` bash
37
51
pyenv install 3.9.16
38
52
pyenv global 3.9.16
@@ -59,9 +73,11 @@ Start LocalStack Pro with the appropriate CORS configuration for the S3 Website:
59
73
LOCALSTACK_API_KEY=... localstack start
60
74
```
61
75
62
- ## Create the infrastructure manually
76
+ ## Instructions
63
77
64
78
You can create the AWS infrastructure on LocalStack by running ` bin/deploy.sh ` .
79
+ Make sure you have Python 3.9 activated before running the script.
80
+
65
81
Here are instructions to deploy it manually step-by-step.
66
82
67
83
### Create the buckets
@@ -185,7 +201,7 @@ awslocal s3 sync --delete ./website s3://webapp
185
201
awslocal s3 website s3://webapp --index-document index.html
186
202
```
187
203
188
- ## Using the app
204
+ ### Using the application
189
205
190
206
Once deployed, visit http://webapp.s3-website.localhost.localstack.cloud:4566
191
207
@@ -204,19 +220,21 @@ An email is then sent with the raw failure message.
204
220
In a real scenario you'd probably have another lambda sitting here, but it's just for demo purposes.
205
221
Since there's no real email server involved, you can use the [ SES developer endpoint] ( https://docs.localstack.cloud/user-guide/aws/ses/ ) to list messages that were sent via SES:
206
222
223
+ ``` bash
207
224
curl -s http://localhost.localstack.cloud:4566/_aws/ses
225
+ ```
208
226
209
227
An alternative is to use a service like MailHog or smtp4dev, and start LocalStack using ` SMTP_HOST=host.docker.internal:1025 ` pointing to the mock SMTP server.
210
228
211
- ## Run integration tests
229
+ ### Run integration tests
212
230
213
231
Once all resource are created on LocalStack, you can run the automated integration tests.
214
232
215
233
``` bash
216
234
pytest tests/
217
235
```
218
236
219
- ## GitHub Action
237
+ ### GitHub Action
220
238
221
239
The demo LocalStack in CI, ` .github/workflows/integration-test.yml ` contains a GitHub Action that starts up LocalStack,
222
240
deploys the infrastructure to it, and then runs the integration tests.
0 commit comments