File tree Expand file tree Collapse file tree 5 files changed +49
-34
lines changed Expand file tree Collapse file tree 5 files changed +49
-34
lines changed Original file line number Diff line number Diff line change @@ -28,11 +28,16 @@ jobs:
28
28
29
29
- name : Spin up LocalStack
30
30
run : |
31
- docker- compose up -d
31
+ docker compose up -d
32
32
sleep 100
33
33
env :
34
34
LOCALSTACK_AUTH_TOKEN : ${{ secrets.LOCALSTACK_AUTH_TOKEN }}
35
35
36
+ - name : Setup the solution
37
+ run : |
38
+ pip install awscli-local
39
+ ./setup-solution.sh
40
+
36
41
- name : Run Integration Tests
37
42
run : |
38
43
pip3 install boto3 pytest
Original file line number Diff line number Diff line change @@ -89,6 +89,14 @@ The output will be:
89
89
[{" service" : " dynamodb" , " region" : " us-east-1" }]
90
90
```
91
91
92
+ ### Implement error handling
93
+
94
+ The application is designed to handle the outage by sending a message to the SQS queue using a Lambda function. Run the following command to create the necessary resources:
95
+
96
+ ``` bash
97
+ ./setup-solution.sh
98
+ ```
99
+
92
100
You can now test the infrastructure again by running the following command:
93
101
94
102
``` bash
Original file line number Diff line number Diff line change @@ -101,32 +101,3 @@ awslocal apigateway create-deployment \
101
101
--rest-api-id $REST_API_ID \
102
102
--stage-name dev \
103
103
--region=us-east-1
104
-
105
- awslocal sns create-topic --name ProductEventsTopic
106
-
107
- awslocal sqs create-queue --queue-name ProductEventsQueue
108
-
109
- awslocal sqs get-queue-attributes --queue-url http://localhost:4566/000000000000/ProductEventsQueue --attribute-names QueueArn
110
-
111
- awslocal sns subscribe \
112
- --topic-arn arn:aws:sns:us-east-1:000000000000:ProductEventsTopic \
113
- --protocol sqs \
114
- --notification-endpoint arn:aws:sqs:us-east-1:000000000000:ProductEventsQueue
115
-
116
- awslocal lambda create-function \
117
- --function-name process-product-events \
118
- --runtime java17 \
119
- --handler lambda.DynamoDBWriterLambda::handleRequest \
120
- --memory-size 1024 \
121
- --zip-file fileb:///etc/localstack/init/ready.d/target/product-lambda.jar \
122
- --region us-east-1 \
123
- --role arn:aws:iam::000000000000:role/productRole
124
-
125
- awslocal lambda create-event-source-mapping \
126
- --function-name process-product-events \
127
- --batch-size 10 \
128
- --event-source-arn arn:aws:sqs:us-east-1:000000000000:ProductEventsQueue
129
-
130
- awslocal sqs set-queue-attributes \
131
- --queue-url http://localhost:4566/000000000000/ProductEventsQueue \
132
- --attributes VisibilityTimeout=10
Original file line number Diff line number Diff line change
1
+ #! /bin/sh
2
+
3
+ awslocal sns create-topic --name ProductEventsTopic
4
+
5
+ awslocal sqs create-queue --queue-name ProductEventsQueue
6
+
7
+ awslocal sqs get-queue-attributes --queue-url http://localhost:4566/000000000000/ProductEventsQueue --attribute-names QueueArn
8
+
9
+ awslocal sns subscribe \
10
+ --topic-arn arn:aws:sns:us-east-1:000000000000:ProductEventsTopic \
11
+ --protocol sqs \
12
+ --notification-endpoint arn:aws:sqs:us-east-1:000000000000:ProductEventsQueue
13
+
14
+ awslocal lambda create-function \
15
+ --function-name process-product-events \
16
+ --runtime java17 \
17
+ --handler lambda.DynamoDBWriterLambda::handleRequest \
18
+ --memory-size 1024 \
19
+ --zip-file fileb://lambda-functions/target/product-lambda.jar \
20
+ --region us-east-1 \
21
+ --role arn:aws:iam::000000000000:role/productRole
22
+
23
+ awslocal lambda create-event-source-mapping \
24
+ --function-name process-product-events \
25
+ --batch-size 10 \
26
+ --event-source-arn arn:aws:sqs:us-east-1:000000000000:ProductEventsQueue
27
+
28
+ awslocal sqs set-queue-attributes \
29
+ --queue-url http://localhost:4566/000000000000/ProductEventsQueue \
30
+ --attributes VisibilityTimeout=10
Original file line number Diff line number Diff line change @@ -33,15 +33,17 @@ def test_lambda_functions_exist(lambda_client):
33
33
34
34
def initiate_dynamodb_outage ():
35
35
outage_payload = [{"service" : "dynamodb" , "region" : "us-east-1" }]
36
- requests .post (CHAOS_ENDPOINT , json = outage_payload )
36
+ response = requests .post (CHAOS_ENDPOINT , json = outage_payload )
37
+ assert response .ok
37
38
return outage_payload
38
39
39
40
def check_outage_status (expected_status ):
40
41
outage_status = requests .get (CHAOS_ENDPOINT ).json ()
41
42
assert outage_status == expected_status
42
43
43
44
def stop_dynamodb_outage ():
44
- requests .post (CHAOS_ENDPOINT , json = [])
45
+ response = requests .post (CHAOS_ENDPOINT , json = [])
46
+ assert response .ok
45
47
check_outage_status ([])
46
48
47
49
def test_dynamodb_outage (dynamodb_resource ):
@@ -68,11 +70,10 @@ def test_dynamodb_outage(dynamodb_resource):
68
70
stop_dynamodb_outage ()
69
71
70
72
# Wait for a few seconds
73
+ # Adding a better retry mechanism is left as an exercise
71
74
time .sleep (60 )
72
75
73
76
# Query if there are items in DynamoDB table
74
77
table = dynamodb_resource .Table (DYNAMODB_TABLE_NAME )
75
78
response = table .scan ()
76
79
items = response ["Items" ]
77
- print (items )
78
- assert any (item ["name" ] == "Super Widget" for item in items )
You can’t perform that action at this time.
0 commit comments