-
Notifications
You must be signed in to change notification settings - Fork 920
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding apigw-sfn-crud-terraform pattern #2444
Open
enmata
wants to merge
1
commit into
aws-samples:main
Choose a base branch
from
enmata:apigw-sfn-crud-terraform_enmata
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,67 @@ | ||
# 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. | ||
|
||
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. Step functions evaluates the path and method to choose the proper action. The action steps can be modified to meet your needs. | ||
|
||
## Testing | ||
|
||
*CRUD = Create, Read, Update, Delete* | ||
|
||
Once the application is deployed, use a tool like Postman or Curl to call the different CRUD endpoints. If you would like to import the Postman package, update the endpoint and import into Postman. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It isn't clear to me what is meant be updating the endpoint and importing it? Please also add an example of a |
||
|
||
## 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,105 @@ | ||
{ | ||
"Comment" : "A description of my state machine", | ||
"StartAt" : "Does ID exist?", | ||
"States" : { | ||
"Does ID exist?" : { | ||
"Type" : "Choice", | ||
"Choices" : [ { | ||
"Variable" : "$.pathParam", | ||
"IsPresent" : true, | ||
"Next" : "Check HTTP Method with ID" | ||
} ], | ||
"Default" : "Check HTTP Method" | ||
}, | ||
"Check HTTP Method" : { | ||
"Type" : "Choice", | ||
"Choices" : [ { | ||
"Variable" : "$.httpMethod", | ||
"StringMatches" : "POST", | ||
"Next" : "Create Item" | ||
} ], | ||
"Default" : "Scan" | ||
}, | ||
"Scan" : { | ||
"Type" : "Task", | ||
"Parameters" : { | ||
"TableName" : "${DDBTable}" | ||
}, | ||
"Resource" : "arn:aws:states:::aws-sdk:dynamodb:scan", | ||
"End" : true | ||
}, | ||
"Create Item" : { | ||
"Type" : "Task", | ||
"Resource" : "arn:aws:states:::dynamodb:putItem", | ||
"Parameters" : { | ||
"TableName" : "${DDBTable}", | ||
"Item" : { | ||
"id" : { | ||
"S.$" : "States.UUID()" | ||
}, | ||
"data" : { | ||
"M.$" : "$.data" | ||
} | ||
} | ||
}, | ||
"ResultPath" : null, | ||
"End" : true | ||
}, | ||
"Check HTTP Method with ID" : { | ||
"Type" : "Choice", | ||
"Choices" : [ { | ||
"Variable" : "$.httpMethod", | ||
"StringMatches" : "PUT", | ||
"Next" : "Update Item" | ||
}, { | ||
"Variable" : "$.httpMethod", | ||
"StringMatches" : "DELETE", | ||
"Next" : "DynamoDB DeleteItem" | ||
} ], | ||
"Default" : "Get Item" | ||
}, | ||
"Get Item" : { | ||
"Type" : "Task", | ||
"Resource" : "arn:aws:states:::dynamodb:getItem", | ||
"Parameters" : { | ||
"TableName" : "${DDBTable}", | ||
"Key" : { | ||
"id" : { | ||
"S.$" : "$.pathParam" | ||
} | ||
} | ||
}, | ||
"End" : true | ||
}, | ||
"Update Item" : { | ||
"Type" : "Task", | ||
"Resource" : "arn:aws:states:::dynamodb:putItem", | ||
"Parameters" : { | ||
"TableName" : "${DDBTable}", | ||
"Item" : { | ||
"id" : { | ||
"S.$" : "$.pathParam" | ||
}, | ||
"data" : { | ||
"M.$" : "$.data" | ||
} | ||
} | ||
}, | ||
"ResultPath" : null, | ||
"End" : true | ||
}, | ||
"DynamoDB DeleteItem" : { | ||
"Type" : "Task", | ||
"Resource" : "arn:aws:states:::dynamodb:deleteItem", | ||
"Parameters" : { | ||
"TableName" : "${DDBTable}", | ||
"Key" : { | ||
"id" : { | ||
"S.$" : "$.pathParam" | ||
} | ||
} | ||
}, | ||
"End" : true | ||
} | ||
} | ||
} |
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,63 @@ | ||
{ | ||
"title": "Amazon API Gateway, AWS Step Functions, to Amazon DynamoDB CRUD API", | ||
"description": "Create a CRUD API with AWS Step Functions.", | ||
"language": "Terraform", | ||
"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": [ | ||
"terraform destroy" | ||
] | ||
}, | ||
"authors": [ | ||
{ | ||
"name": "Oriol Matavacas", | ||
"image": "https://togithub.s3.eu-west-1.amazonaws.com/Oriol.jpg", | ||
"bio": "Oriol Matavacas is a Sr. Solutions Architect at AWS based in Barcelona. Oriol primarily supporting customers on the journey to the Cloud. He enjoys building new solutions with scalability, availability and easy to maintain by using serverless.", | ||
"linkedin": "https://www.linkedin.com/in/oriol-matavacas-rodriguez-b165868a", | ||
"twitter": "" | ||
} | ||
] | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.