Skip to content

Commit 399b979

Browse files
committed
setup the application
0 parents  commit 399b979

File tree

12 files changed

+707
-0
lines changed

12 files changed

+707
-0
lines changed

.github/workflows/ci.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Run Integration Tests
2+
3+
on:
4+
push:
5+
paths-ignore:
6+
- 'README.md'
7+
branches:
8+
- main
9+
pull_request:
10+
branches:
11+
- main
12+
13+
jobs:
14+
cdk:
15+
name: Chaos Testing
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v3
20+
21+
- uses: actions/setup-java@v4
22+
with:
23+
distribution: 'temurin'
24+
java-version: '21'
25+
26+
- name: Build Lambdas
27+
run: cd lambda-functions && mvn clean package shade:shade
28+
29+
- name: Spin up LocalStack
30+
run: |
31+
docker-compose up -d
32+
sleep 100
33+
env:
34+
LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }}
35+
36+
- name: Run Integration Tests
37+
run: |
38+
pip3 install boto3 pytest
39+
pytest
40+
env:
41+
AWS_DEFAULT_REGION: us-east-1
42+
AWS_REGION: us-east-1
43+
AWS_ACCESS_KEY_ID: test
44+
AWS_SECRET_ACCESS_KEY: test

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# LocalStack
2+
3+
volume/

docker-compose.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
version: "3.9"
2+
3+
services:
4+
localstack:
5+
networks:
6+
- ls_network
7+
container_name: localstack
8+
image: localstack/localstack-pro:latest
9+
ports:
10+
- "127.0.0.1:4566:4566" # LocalStack Gateway
11+
- "127.0.0.1:4510-4559:4510-4559" # external services port range
12+
- "127.0.0.1:443:443"
13+
environment:
14+
- DOCKER_HOST=unix:///var/run/docker.sock #unix socket to communicate with the docker daemon
15+
- LOCALSTACK_HOST=localstack # where services are available from other containers
16+
- LAMBDA_DOCKER_NETWORK=ls_network
17+
- LOCALSTACK_AUTH_TOKEN=${LOCALSTACK_AUTH_TOKEN:?}
18+
- LAMBDA_RUNTIME_ENVIRONMENT_TIMEOUT=60
19+
- PERSIST_ALL=false
20+
- EXTENSION_AUTO_INSTALL=localstack-extension-outages
21+
- LAMBDA_RUNTIME_ENVIRONMENT_TIMEOUT=600
22+
volumes:
23+
- "./volume:/var/lib/localstack"
24+
- "/var/run/docker.sock:/var/run/docker.sock"
25+
- "./lambda-functions/target/product-lambda.jar:/etc/localstack/init/ready.d/target/product-lambda.jar"
26+
- "./init-resources.sh:/etc/localstack/init/ready.d/init-resources.sh"
27+
28+
networks:
29+
ls_network:
30+
name: ls_network

init-resources.sh

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
#!/bin/sh
2+
3+
apt-get -y install jq
4+
5+
echo "Create DynamoDB table..."
6+
awslocal dynamodb create-table \
7+
--table-name Products \
8+
--attribute-definitions AttributeName=id,AttributeType=S \
9+
--key-schema AttributeName=id,KeyType=HASH \
10+
--provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5 \
11+
--region us-east-1
12+
13+
echo "Add Product Lambda..."
14+
awslocal lambda create-function \
15+
--function-name add-product \
16+
--runtime java17 \
17+
--handler lambda.AddProduct::handleRequest \
18+
--memory-size 1024 \
19+
--zip-file fileb:///etc/localstack/init/ready.d/target/product-lambda.jar \
20+
--region us-east-1 \
21+
--role arn:aws:iam::000000000000:role/productRole \
22+
--environment Variables={AWS_REGION=us-east-1}
23+
24+
echo "Get Product Lambda..."
25+
awslocal lambda create-function \
26+
--function-name get-product \
27+
--runtime java17 \
28+
--handler lambda.GetProduct::handleRequest \
29+
--memory-size 1024 \
30+
--zip-file fileb:///etc/localstack/init/ready.d/target/product-lambda.jar \
31+
--region us-east-1 \
32+
--role arn:aws:iam::000000000000:role/productRole \
33+
--environment Variables={AWS_REGION=us-east-1}
34+
35+
export REST_API_ID=12345
36+
37+
echo "Create Rest API..."
38+
awslocal apigateway create-rest-api --name quote-api-gateway --tags '{"_custom_id_":"12345"}' --region us-east-1
39+
40+
echo "Export Parent ID..."
41+
export PARENT_ID=$(awslocal apigateway get-resources --rest-api-id $REST_API_ID --region=us-east-1 | jq -r '.items[0].id')
42+
43+
echo "Export Resource ID..."
44+
export RESOURCE_ID=$(awslocal apigateway create-resource --rest-api-id $REST_API_ID --parent-id $PARENT_ID --path-part "productApi" --region=us-east-1 | jq -r '.id')
45+
46+
echo "RESOURCE ID:"
47+
echo $RESOURCE
48+
49+
echo "Put GET Method..."
50+
awslocal apigateway put-method \
51+
--rest-api-id $REST_API_ID \
52+
--resource-id $RESOURCE_ID \
53+
--http-method GET \
54+
--request-parameters "method.request.path.productApi=true" \
55+
--authorization-type "NONE" \
56+
--region=us-east-1
57+
58+
echo "Put POST Method..."
59+
awslocal apigateway put-method \
60+
--rest-api-id $REST_API_ID \
61+
--resource-id $RESOURCE_ID \
62+
--http-method POST \
63+
--request-parameters "method.request.path.productApi=true" \
64+
--authorization-type "NONE" \
65+
--region=us-east-1
66+
67+
68+
echo "Update GET Method..."
69+
awslocal apigateway update-method \
70+
--rest-api-id $REST_API_ID \
71+
--resource-id $RESOURCE_ID \
72+
--http-method GET \
73+
--patch-operations "op=replace,path=/requestParameters/method.request.querystring.param,value=true" \
74+
--region=us-east-1
75+
76+
77+
echo "Put POST Method Integration..."
78+
awslocal apigateway put-integration \
79+
--rest-api-id $REST_API_ID \
80+
--resource-id $RESOURCE_ID \
81+
--http-method POST \
82+
--type AWS_PROXY \
83+
--integration-http-method POST \
84+
--uri arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:000000000000:function:add-product/invocations \
85+
--passthrough-behavior WHEN_NO_MATCH \
86+
--region=us-east-1
87+
88+
echo "Put GET Method Integration..."
89+
awslocal apigateway put-integration \
90+
--rest-api-id $REST_API_ID \
91+
--resource-id $RESOURCE_ID \
92+
--http-method GET \
93+
--type AWS_PROXY \
94+
--integration-http-method GET \
95+
--uri arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:000000000000:function:get-product/invocations \
96+
--passthrough-behavior WHEN_NO_MATCH \
97+
--region=us-east-1
98+
99+
echo "Create DEV Deployment..."
100+
awslocal apigateway create-deployment \
101+
--rest-api-id $REST_API_ID \
102+
--stage-name dev \
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

lambda-functions/pom.xml

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
6+
<modelVersion>4.0.0</modelVersion>
7+
8+
<artifactId>product-lambda</artifactId>
9+
<groupId>cloud.localstack</groupId>
10+
<packaging>jar</packaging>
11+
<version>1.0-SNAPSHOT</version>
12+
13+
<properties>
14+
<maven.compiler.source>17</maven.compiler.source>
15+
<maven.compiler.target>17</maven.compiler.target>
16+
<exec.cleanupDaemonThreads>false</exec.cleanupDaemonThreads>
17+
</properties>
18+
19+
<dependencies>
20+
<dependency>
21+
<groupId>software.amazon.awssdk</groupId>
22+
<artifactId>lambda</artifactId>
23+
</dependency>
24+
<dependency>
25+
<groupId>com.amazonaws</groupId>
26+
<artifactId>aws-lambda-java-core</artifactId>
27+
<version>1.2.2</version>
28+
</dependency>
29+
<dependency>
30+
<groupId>software.amazon.awssdk</groupId>
31+
<artifactId>protocol-core</artifactId>
32+
<version>2.20.69</version>
33+
</dependency>
34+
<dependency>
35+
<groupId>software.amazon.awssdk</groupId>
36+
<artifactId>s3</artifactId>
37+
</dependency>
38+
<dependency>
39+
<groupId>software.amazon.awssdk</groupId>
40+
<artifactId>dynamodb</artifactId>
41+
<version>2.20.68</version>
42+
</dependency>
43+
<dependency>
44+
<groupId>com.amazonaws</groupId>
45+
<artifactId>aws-lambda-java-events</artifactId>
46+
<version>3.11.3</version>
47+
</dependency>
48+
<!-- Jackson Core -->
49+
<dependency>
50+
<groupId>com.fasterxml.jackson.core</groupId>
51+
<artifactId>jackson-core</artifactId>
52+
<version>2.13.3</version>
53+
</dependency>
54+
55+
<!-- Jackson Databind -->
56+
<dependency>
57+
<groupId>com.fasterxml.jackson.core</groupId>
58+
<artifactId>jackson-databind</artifactId>
59+
<version>2.13.3</version>
60+
</dependency>
61+
62+
<!-- Jackson Annotations -->
63+
<dependency>
64+
<groupId>com.fasterxml.jackson.core</groupId>
65+
<artifactId>jackson-annotations</artifactId>
66+
<version>2.15.1</version>
67+
</dependency>
68+
<dependency>
69+
<groupId>software.amazon.awssdk</groupId>
70+
<artifactId>sns</artifactId>
71+
<version>2.20.69</version>
72+
</dependency>
73+
<!-- SLF4J API -->
74+
<dependency>
75+
<groupId>org.slf4j</groupId>
76+
<artifactId>slf4j-api</artifactId>
77+
<version>2.0.7</version>
78+
</dependency>
79+
<!-- Logback Classic Implementation -->
80+
<dependency>
81+
<groupId>ch.qos.logback</groupId>
82+
<artifactId>logback-classic</artifactId>
83+
<version>1.4.7</version>
84+
</dependency>
85+
86+
</dependencies>
87+
88+
<dependencyManagement>
89+
<dependencies>
90+
<dependency>
91+
<groupId>software.amazon.awssdk</groupId>
92+
<artifactId>bom</artifactId>
93+
<version>2.20.47</version>
94+
<type>pom</type>
95+
<scope>import</scope>
96+
</dependency>
97+
</dependencies>
98+
</dependencyManagement>
99+
100+
<build>
101+
<finalName>product-lambda</finalName>
102+
<resources>
103+
<resource>
104+
<directory>src/main/resources</directory>
105+
<filtering>true</filtering>
106+
</resource>
107+
</resources>
108+
109+
<plugins>
110+
<plugin>
111+
<groupId>org.apache.maven.plugins</groupId>
112+
<artifactId>maven-shade-plugin</artifactId>
113+
<version>2.4.3</version>
114+
<configuration>
115+
<createDependencyReducedPom>false</createDependencyReducedPom>
116+
</configuration>
117+
<executions>
118+
<execution>
119+
<phase>package</phase>
120+
<goals>
121+
<goal>shade</goal>
122+
</goals>
123+
</execution>
124+
</executions>
125+
</plugin>
126+
</plugins>
127+
</build>
128+
</project>

0 commit comments

Comments
 (0)