Skip to content

Commit 4e5a943

Browse files
authored
Merge pull request #2444 from enmata/apigw-sfn-crud-terraform_enmata
Adding apigw-sfn-crud-terraform pattern
2 parents c6a8c9b + 8065b1a commit 4e5a943

File tree

6 files changed

+871
-0
lines changed

6 files changed

+871
-0
lines changed
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
{
2+
"info": {
3+
"_postman_id": "1045b2bc-58ae-4a8d-9f0b-35d5cb44e266",
4+
"name": "Random",
5+
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
6+
"_exporter_id": "8276188"
7+
},
8+
"variable": [
9+
{
10+
"key": "endpoint",
11+
"value": "<your endpoint here>",
12+
"type": "string"
13+
},
14+
{
15+
"key": "id",
16+
"value": "<your id>",
17+
"type": "string"
18+
}
19+
],
20+
"item": [
21+
{
22+
"name": "DDB Read All",
23+
"request": {
24+
"method": "GET",
25+
"header": [],
26+
"url": {
27+
"raw": "{{endpoint}}",
28+
"host": [
29+
"{{endpoint}}"
30+
]
31+
}
32+
},
33+
"response": []
34+
},
35+
{
36+
"name": "DDB Read One",
37+
"request": {
38+
"method": "GET",
39+
"header": [],
40+
"url": {
41+
"raw": "{{endpoint}}/{{id}}",
42+
"host": [
43+
"{{endpoint}}"
44+
],
45+
"path": [
46+
"{{id}}"
47+
]
48+
}
49+
},
50+
"response": []
51+
},
52+
{
53+
"name": "DDB Delete",
54+
"request": {
55+
"method": "DELETE",
56+
"header": [],
57+
"url": {
58+
"raw": "{{endpoint}}/{{id}}",
59+
"host": [
60+
"{{endpoint}}"
61+
],
62+
"path": [
63+
"{{id}}"
64+
]
65+
}
66+
},
67+
"response": []
68+
},
69+
{
70+
"name": "DDB Create",
71+
"request": {
72+
"method": "POST",
73+
"header": [],
74+
"body": {
75+
"mode": "raw",
76+
"raw": "{\n \"make\":\"MINI\",\n \"model\": \"Countryman\",\n \"year\": 2015,\n \"trim\": \"JCW All Four\"\n}",
77+
"options": {
78+
"raw": {
79+
"language": "json"
80+
}
81+
}
82+
},
83+
"url": {
84+
"raw": "{{endpoint}}",
85+
"host": [
86+
"{{endpoint}}"
87+
]
88+
}
89+
},
90+
"response": []
91+
},
92+
{
93+
"name": "DDB Update",
94+
"request": {
95+
"method": "PUT",
96+
"header": [],
97+
"body": {
98+
"mode": "raw",
99+
"raw": "{\"message\":\"my message again from postman\"}",
100+
"options": {
101+
"raw": {
102+
"language": "json"
103+
}
104+
}
105+
},
106+
"url": {
107+
"raw": "{{endpoint}}/{{id}}",
108+
"host": [
109+
"{{endpoint}}"
110+
],
111+
"path": [
112+
"{{id}}"
113+
]
114+
}
115+
},
116+
"response": []
117+
}
118+
],
119+
"event": [
120+
{
121+
"listen": "prerequest",
122+
"script": {
123+
"type": "text/javascript",
124+
"exec": [
125+
""
126+
]
127+
}
128+
},
129+
{
130+
"listen": "test",
131+
"script": {
132+
"type": "text/javascript",
133+
"exec": [
134+
""
135+
]
136+
}
137+
}
138+
]
139+
}

apigw-sfn-crud-terraform/README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Amazon API Gateway, AWS Step Functions, to Amazon DynamoDB CRUD API
2+
3+
This stack creates a fully functioning CRUD API powered by Amazon API Gateway direct integration to AWS Step Functions and backed by Amazon DynamoDB.
4+
5+
*CRUD = Create, Read, Update, Delete*
6+
7+
Learn more about this pattern at Serverless Land Patterns: https://serverlessland.com/patterns/apigw-sfn-crud-terraform
8+
9+
Important: this application uses various AWS services and there are costs associated with these services after the Free Tier usage - please see the [AWS Pricing page](https://aws.amazon.com/pricing/) for details. You are responsible for any AWS costs incurred. No warranty is implied in this example.
10+
11+
## Requirements
12+
13+
* [Create an AWS account](https://portal.aws.amazon.com/gp/aws/developer/registration/index.html) if you do not already have one and log in. The IAM user that you use must have sufficient permissions to make necessary AWS service calls and manage AWS resources.
14+
* [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html) installed and configured
15+
* [Git Installed](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
16+
* [Terraform](https://learn.hashicorp.com/tutorials/terraform/install-cli?in=terraform/aws-get-started) installed
17+
18+
## Deployment Instructions
19+
20+
1. Create a new directory, navigate to that directory in a terminal and clone the GitHub repository:
21+
```
22+
git clone https://github.com/aws-samples/serverless-patterns
23+
```
24+
2. Change directory to the pattern directory:
25+
```
26+
cd apigw-sfn-crud-terraform
27+
```
28+
3. From the command line, initialize terraform to download and install the providers defined in the configuration:
29+
```
30+
terraform init
31+
```
32+
4. From the command line, apply the configuration in the main.tf file:
33+
```
34+
terraform apply
35+
```
36+
5. During the prompts:
37+
* Enter yes
38+
6. Note the outputs from the deployment process. These contain the resource names and/or URLs which are used for testing.
39+
40+
## How it works
41+
42+
Amazon API Gateway creates a direct integration with AWS Step Functions utilizing a synchronous call. The Step Functions state machine evaluates the path and method to choose the proper action. The action steps can be modified to meet your needs.
43+
44+
## Testing
45+
46+
Once your application is up and running, you can verify the CRUD operations in two ways:
47+
- Make a curl request directly to the endpoint shown in the Terraform output
48+
- Use Postman by importing the provided collection file (make sure to update the endpoint URLs to match your deployed environment)
49+
50+
Both methods will allow you to test and interact with your API endpoints.
51+
52+
## Cleanup
53+
1. Change directory to the pattern directory:
54+
```
55+
cd apigw-sfn-crud-terraform
56+
```
57+
2. Delete all created resources by terraform
58+
```bash
59+
terraform destroy
60+
```
61+
3. During the prompts:
62+
* Enter yes
63+
4. Confirm all created resources has been deleted
64+
```bash
65+
terraform show
66+
```
67+
----
68+
Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
69+
70+
SPDX-License-Identifier: MIT-0
71+
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
{
2+
"title": "Amazon API Gateway, AWS Step Functions, to Amazon DynamoDB CRUD API",
3+
"description": "Create a CRUD API with AWS Step Functions.",
4+
"language": "",
5+
"level": "200",
6+
"framework": "Terraform",
7+
"introBox": {
8+
"headline": "Create a CRUD API with AWS Step Functions.",
9+
"text": [
10+
"This stack creates a fully functioning CRUD API powered by Amazon API Gateway direct integration to AWS Step Functions and backed by Amazon DynamoDB."
11+
]
12+
},
13+
"gitHub": {
14+
"template": {
15+
"repoURL": "https://github.com/aws-samples/serverless-patterns/tree/main/apigw-sfn-crud-terraform",
16+
"templateURL": "serverless-patterns/apigw-sfn-crud-terraform",
17+
"projectFolder": "apigw-sfn-crud-terraform",
18+
"templateFile": "main.tf"
19+
}
20+
},
21+
"resources": {
22+
"bullets": [
23+
{
24+
"text": "Synchronous Express Workflows for AWS Step Functions",
25+
"link": "https://aws.amazon.com/blogs/compute/new-synchronous-express-workflows-for-aws-step-functions"
26+
},
27+
{
28+
"text": "API Gateway VTL",
29+
"link": "https://docs.aws.amazon.com/apigateway/latest/developerguide/rest-api-data-transformations.html"
30+
},
31+
{
32+
"text": "Simple CRUD with API Gateway & DynamboDB",
33+
"link": "https://github.com/aws-samples/serverless-patterns/tree/main/apigw-ddb-openapi-crud"
34+
}
35+
]
36+
},
37+
"deploy": {
38+
"text": [
39+
"terraform init",
40+
"terraform apply"
41+
]
42+
},
43+
"testing": {
44+
"text": [
45+
"See the GitHub repo for detailed testing instructions."
46+
]
47+
},
48+
"cleanup": {
49+
"text": [
50+
"<code>terraform destroy</code>"
51+
]
52+
},
53+
"authors": [
54+
{
55+
"name": "Oriol Matavacas",
56+
"image": "https://togithub.s3.eu-west-1.amazonaws.com/Oriol.jpg",
57+
"bio": "Oriol Matavacas is a Senior Solutions Architect at AWS based in Barcelona. Oriol primarily supports customers on the journey to the Cloud. He enjoys building new solutions with scalability, availability and easy to maintain by using serverless.",
58+
"linkedin": "oriol-matavacas-rodriguez-b165868a",
59+
"twitter": ""
60+
}
61+
],
62+
"patternArch": {
63+
"icon1": {
64+
"x": 20,
65+
"y": 50,
66+
"service": "apigw",
67+
"label": "API Gateway REST API"
68+
},
69+
"icon2": {
70+
"x": 50,
71+
"y": 50,
72+
"service": "sfn",
73+
"label": "AWS Step Functions"
74+
},
75+
"icon3": {
76+
"x": 80,
77+
"y": 50,
78+
"service": "dynamodb",
79+
"label": "Amazon DynamoDB"
80+
},
81+
"line1": {
82+
"from": "icon1",
83+
"to": "icon2",
84+
"label": ""
85+
},
86+
"line2": {
87+
"from": "icon2",
88+
"to": "icon3",
89+
"label": ""
90+
}
91+
}
92+
}

0 commit comments

Comments
 (0)