Skip to content

Commit 0aa17e2

Browse files
committed
update app to work with latest localstack version
1 parent 73a07d6 commit 0aa17e2

File tree

4 files changed

+61
-13
lines changed

4 files changed

+61
-13
lines changed

README.md

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,50 @@ A serverless application that demos several AWS functionalities on LocalStack:
1414

1515
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.
1616

17+
Here's the app in action:
18+
1719
## Overview
1820

1921
![Screenshot at 2022-11-23 16-34-12](https://user-images.githubusercontent.com/3996682/203586505-e54ccb3e-5101-4ee8-917d-d6372ee965ef.png)
2022

2123
## Prerequisites
2224

23-
Make sure you use the same version as the Python Lambdas to make Pillow work (3.9)
25+
### Dev environment
26+
27+
Make sure you use the same version as the Python Lambdas to make Pillow work.
28+
If you use pyenv, then first install and activate Python 3.9:
29+
```bash
30+
pyenv install 3.9.16
31+
pyenv global 3.9.16
32+
```
33+
34+
```console
35+
% python --version
36+
Python 3.9.16
37+
```
38+
39+
Create a virtualenv and install all the development dependencies there:
40+
41+
```bash
42+
python -m venv .venv
43+
source .venv/bin/activate
44+
pip install -r requirements-dev.txt
45+
```
46+
47+
### LocalStack
48+
49+
Start LocalStack Pro with the appropriate CORS configuration for the S3 Website:
50+
51+
```bash
52+
export EXTRA_CORS_ALLOWED_ORIGINS=webapp.s3-website.localhost.localstack.cloud:4566
53+
LOCALSTACK_API_KEY=... localstack start
54+
```
2455

2556
## Create the infrastructure manually
2657

58+
You can create the AWS infrastructure on LocalStack by running `bin/deploy.sh`.
59+
Here are instructions to deploy it manually step-by-step.
60+
2761
### Create the buckets
2862

2963
The names are completely configurable via SSM:
@@ -36,8 +70,8 @@ awslocal s3 mb s3://localstack-thumbnails-app-resized
3670
### Put the bucket names into the parameter store
3771

3872
```bash
39-
awslocal ssm put-parameter --name /localstack-thumbnail-app/buckets/images --value "localstack-thumbnails-app-images"
40-
awslocal ssm put-parameter --name /localstack-thumbnail-app/buckets/resized --value "localstack-thumbnails-app-resized"
73+
awslocal ssm put-parameter --name /localstack-thumbnail-app/buckets/images --type "String" --value "localstack-thumbnails-app-images"
74+
awslocal ssm put-parameter --name /localstack-thumbnail-app/buckets/resized --type "String" --value "localstack-thumbnails-app-resized"
4175
```
4276

4377
### Create the DLQ Topic for failed lambda invokes
@@ -81,7 +115,7 @@ awslocal lambda create-function-url-config \
81115
--auth-type NONE
82116
```
83117

84-
Copy the `FunctionUrl` from the response!
118+
Copy the `FunctionUrl` from the response, you will need it later to make the app work.
85119

86120
### Resizer Lambda
87121

@@ -121,15 +155,27 @@ awslocal s3 sync --delete ./website s3://webapp
121155
awslocal s3 website s3://webapp --index-document index.html
122156
```
123157

124-
Then visit http://webapp.s3-website.localhost.localstack.cloud:4566
158+
## Using the app
125159

160+
Once deployed, visit http://webapp.s3-website.localhost.localstack.cloud:4566
126161

127-
## Develop locally
162+
Paste the Function URL of the presign Lambda you created earlier into the form field.
163+
If you use LocalStack's v2 Lambda provider then you can also get the URL by running:
164+
```bash
165+
awslocal lambda list-function-url-configs --function-name presign
166+
```
128167

129-
Create a virtualenv and install all the dependencies there:
168+
After uploading a file, you can download the resized file from the `localstack-thumbnails-app-resized` bucket.
169+
170+
## Run integration tests
171+
172+
Once all resource are created on LocalStack, you can run the automated integration tests.
130173

131174
```bash
132-
python3 -m venv .venv
133-
source .venv/bin/activate
134-
pip install -r requirements-dev.txt
175+
pytest tests/
135176
```
177+
178+
## GitHub Action
179+
180+
The demo LocalStack in CI, `.github/workflows/integration-test.yml` contains a GitHub Action that starts up LocalStack,
181+
deploys the infrastructure to it, and then runs the integration tests.

bin/deploy.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
awslocal s3 mb s3://localstack-thumbnails-app-images
44
awslocal s3 mb s3://localstack-thumbnails-app-resized
55

6-
awslocal ssm put-parameter --name /localstack-thumbnail-app/buckets/images --value "localstack-thumbnails-app-images"
7-
awslocal ssm put-parameter --name /localstack-thumbnail-app/buckets/resized --value "localstack-thumbnails-app-resized"
6+
awslocal ssm put-parameter --name /localstack-thumbnail-app/buckets/images --type "String" --value "localstack-thumbnails-app-images"
7+
awslocal ssm put-parameter --name /localstack-thumbnail-app/buckets/resized --type "String" --value "localstack-thumbnails-app-resized"
88

99
awslocal sns create-topic --name failed-resize-topic
1010
awslocal sns subscribe \

requirements-dev.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ mypy_boto3_sns
66
mypy_boto3_s3
77
black
88
pytest
9+
awscli
10+
awscli-local

tests/test_integration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def test_failure_sns_to_ses_integration():
6060
s3.upload_file(file, Bucket=source_bucket, Key=key)
6161

6262
def _check_message():
63-
response = requests.get("http://localhost:4566/_localstack/ses")
63+
response = requests.get("http://localhost:4566/_aws/ses")
6464
messages = response.json()["messages"]
6565
assert key in messages[-1]["Body"]["text_part"]
6666

0 commit comments

Comments
 (0)