-
Notifications
You must be signed in to change notification settings - Fork 943
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2444 from enmata/apigw-sfn-crud-terraform_enmata
Adding apigw-sfn-crud-terraform pattern
- Loading branch information
Showing
6 changed files
with
871 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
{ | ||
"info": { | ||
"_postman_id": "1045b2bc-58ae-4a8d-9f0b-35d5cb44e266", | ||
"name": "Random", | ||
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", | ||
"_exporter_id": "8276188" | ||
}, | ||
"variable": [ | ||
{ | ||
"key": "endpoint", | ||
"value": "<your endpoint here>", | ||
"type": "string" | ||
}, | ||
{ | ||
"key": "id", | ||
"value": "<your id>", | ||
"type": "string" | ||
} | ||
], | ||
"item": [ | ||
{ | ||
"name": "DDB Read All", | ||
"request": { | ||
"method": "GET", | ||
"header": [], | ||
"url": { | ||
"raw": "{{endpoint}}", | ||
"host": [ | ||
"{{endpoint}}" | ||
] | ||
} | ||
}, | ||
"response": [] | ||
}, | ||
{ | ||
"name": "DDB Read One", | ||
"request": { | ||
"method": "GET", | ||
"header": [], | ||
"url": { | ||
"raw": "{{endpoint}}/{{id}}", | ||
"host": [ | ||
"{{endpoint}}" | ||
], | ||
"path": [ | ||
"{{id}}" | ||
] | ||
} | ||
}, | ||
"response": [] | ||
}, | ||
{ | ||
"name": "DDB Delete", | ||
"request": { | ||
"method": "DELETE", | ||
"header": [], | ||
"url": { | ||
"raw": "{{endpoint}}/{{id}}", | ||
"host": [ | ||
"{{endpoint}}" | ||
], | ||
"path": [ | ||
"{{id}}" | ||
] | ||
} | ||
}, | ||
"response": [] | ||
}, | ||
{ | ||
"name": "DDB Create", | ||
"request": { | ||
"method": "POST", | ||
"header": [], | ||
"body": { | ||
"mode": "raw", | ||
"raw": "{\n \"make\":\"MINI\",\n \"model\": \"Countryman\",\n \"year\": 2015,\n \"trim\": \"JCW All Four\"\n}", | ||
"options": { | ||
"raw": { | ||
"language": "json" | ||
} | ||
} | ||
}, | ||
"url": { | ||
"raw": "{{endpoint}}", | ||
"host": [ | ||
"{{endpoint}}" | ||
] | ||
} | ||
}, | ||
"response": [] | ||
}, | ||
{ | ||
"name": "DDB Update", | ||
"request": { | ||
"method": "PUT", | ||
"header": [], | ||
"body": { | ||
"mode": "raw", | ||
"raw": "{\"message\":\"my message again from postman\"}", | ||
"options": { | ||
"raw": { | ||
"language": "json" | ||
} | ||
} | ||
}, | ||
"url": { | ||
"raw": "{{endpoint}}/{{id}}", | ||
"host": [ | ||
"{{endpoint}}" | ||
], | ||
"path": [ | ||
"{{id}}" | ||
] | ||
} | ||
}, | ||
"response": [] | ||
} | ||
], | ||
"event": [ | ||
{ | ||
"listen": "prerequest", | ||
"script": { | ||
"type": "text/javascript", | ||
"exec": [ | ||
"" | ||
] | ||
} | ||
}, | ||
{ | ||
"listen": "test", | ||
"script": { | ||
"type": "text/javascript", | ||
"exec": [ | ||
"" | ||
] | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# Amazon API Gateway, AWS Step Functions, to Amazon DynamoDB CRUD API | ||
|
||
This stack creates a fully functioning CRUD API powered by Amazon API Gateway direct integration to AWS Step Functions and backed by Amazon DynamoDB. | ||
|
||
*CRUD = Create, Read, Update, Delete* | ||
|
||
Learn more about this pattern at Serverless Land Patterns: https://serverlessland.com/patterns/apigw-sfn-crud-terraform | ||
|
||
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. | ||
|
||
## Requirements | ||
|
||
* [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. | ||
* [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html) installed and configured | ||
* [Git Installed](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) | ||
* [Terraform](https://learn.hashicorp.com/tutorials/terraform/install-cli?in=terraform/aws-get-started) installed | ||
|
||
## Deployment Instructions | ||
|
||
1. Create a new directory, navigate to that directory in a terminal and clone the GitHub repository: | ||
``` | ||
git clone https://github.com/aws-samples/serverless-patterns | ||
``` | ||
2. Change directory to the pattern directory: | ||
``` | ||
cd apigw-sfn-crud-terraform | ||
``` | ||
3. From the command line, initialize terraform to download and install the providers defined in the configuration: | ||
``` | ||
terraform init | ||
``` | ||
4. From the command line, apply the configuration in the main.tf file: | ||
``` | ||
terraform apply | ||
``` | ||
5. During the prompts: | ||
* Enter yes | ||
6. Note the outputs from the deployment process. These contain the resource names and/or URLs which are used for testing. | ||
## How it works | ||
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. | ||
## Testing | ||
Once your application is up and running, you can verify the CRUD operations in two ways: | ||
- Make a curl request directly to the endpoint shown in the Terraform output | ||
- Use Postman by importing the provided collection file (make sure to update the endpoint URLs to match your deployed environment) | ||
Both methods will allow you to test and interact with your API endpoints. | ||
## Cleanup | ||
1. Change directory to the pattern directory: | ||
``` | ||
cd apigw-sfn-crud-terraform | ||
``` | ||
2. Delete all created resources by terraform | ||
```bash | ||
terraform destroy | ||
``` | ||
3. During the prompts: | ||
* Enter yes | ||
4. Confirm all created resources has been deleted | ||
```bash | ||
terraform show | ||
``` | ||
---- | ||
Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
SPDX-License-Identifier: MIT-0 | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
{ | ||
"title": "Amazon API Gateway, AWS Step Functions, to Amazon DynamoDB CRUD API", | ||
"description": "Create a CRUD API with AWS Step Functions.", | ||
"language": "", | ||
"level": "200", | ||
"framework": "Terraform", | ||
"introBox": { | ||
"headline": "Create a CRUD API with AWS Step Functions.", | ||
"text": [ | ||
"This stack creates a fully functioning CRUD API powered by Amazon API Gateway direct integration to AWS Step Functions and backed by Amazon DynamoDB." | ||
] | ||
}, | ||
"gitHub": { | ||
"template": { | ||
"repoURL": "https://github.com/aws-samples/serverless-patterns/tree/main/apigw-sfn-crud-terraform", | ||
"templateURL": "serverless-patterns/apigw-sfn-crud-terraform", | ||
"projectFolder": "apigw-sfn-crud-terraform", | ||
"templateFile": "main.tf" | ||
} | ||
}, | ||
"resources": { | ||
"bullets": [ | ||
{ | ||
"text": "Synchronous Express Workflows for AWS Step Functions", | ||
"link": "https://aws.amazon.com/blogs/compute/new-synchronous-express-workflows-for-aws-step-functions" | ||
}, | ||
{ | ||
"text": "API Gateway VTL", | ||
"link": "https://docs.aws.amazon.com/apigateway/latest/developerguide/rest-api-data-transformations.html" | ||
}, | ||
{ | ||
"text": "Simple CRUD with API Gateway & DynamboDB", | ||
"link": "https://github.com/aws-samples/serverless-patterns/tree/main/apigw-ddb-openapi-crud" | ||
} | ||
] | ||
}, | ||
"deploy": { | ||
"text": [ | ||
"terraform init", | ||
"terraform apply" | ||
] | ||
}, | ||
"testing": { | ||
"text": [ | ||
"See the GitHub repo for detailed testing instructions." | ||
] | ||
}, | ||
"cleanup": { | ||
"text": [ | ||
"<code>terraform destroy</code>" | ||
] | ||
}, | ||
"authors": [ | ||
{ | ||
"name": "Oriol Matavacas", | ||
"image": "https://togithub.s3.eu-west-1.amazonaws.com/Oriol.jpg", | ||
"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.", | ||
"linkedin": "oriol-matavacas-rodriguez-b165868a", | ||
"twitter": "" | ||
} | ||
], | ||
"patternArch": { | ||
"icon1": { | ||
"x": 20, | ||
"y": 50, | ||
"service": "apigw", | ||
"label": "API Gateway REST API" | ||
}, | ||
"icon2": { | ||
"x": 50, | ||
"y": 50, | ||
"service": "sfn", | ||
"label": "AWS Step Functions" | ||
}, | ||
"icon3": { | ||
"x": 80, | ||
"y": 50, | ||
"service": "dynamodb", | ||
"label": "Amazon DynamoDB" | ||
}, | ||
"line1": { | ||
"from": "icon1", | ||
"to": "icon2", | ||
"label": "" | ||
}, | ||
"line2": { | ||
"from": "icon2", | ||
"to": "icon3", | ||
"label": "" | ||
} | ||
} | ||
} |
Oops, something went wrong.