Skip to content

Instantly share code, notes, and snippets.

@thanakijwanavit
Last active January 5, 2021 14:56
Show Gist options
  • Save thanakijwanavit/03cf1308e1add5ecb24a62c65f81cf71 to your computer and use it in GitHub Desktop.
Save thanakijwanavit/03cf1308e1add5ecb24a62c65f81cf71 to your computer and use it in GitHub Desktop.
example of dynamodb crud app template
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
shortenLink
Sample SAM Template for shortenLink
Globals:
Function:
Timeout: 3
Runtime: python3.8
MemorySize: 128
CodeUri: locationApp/
Resources:
Locations:
Type: AWS::DynamoDB::Table
Properties:
AttributeDefinitions:
- AttributeName: id
AttributeType: S
- AttributeName: city
AttributeType: S
BillingMode: PAY_PER_REQUEST
KeySchema:
- AttributeName: id
KeyType: HASH
LocalSecondaryIndexes:
- IndexName: name
KeySchema:
- AttributeName: name
KeyType: HASH
Projection:
ProjectionType: ALL
- IndexName: city
KeySchema:
- AttributeName: city
KeyType: HASH
Projection:
ProjectionType: ALL
PointInTimeRecoverySpecification:
PointInTimeRecoveryEnabled: true
TableName: !Join [ "-" , ["locations", !Ref BRANCH]]
Add:
Type: AWS::Serverless::Function
Properties:
Handler: app.add
Policies:
- DynamoDBCrudPolicy:
TableName: !Ref Locations
Events:
ShortenLinkEvent:
Type: Api
Properties:
Path: /add
Method: post
RestApiId: !Ref ApiGateway
Remove:
Type: AWS::Serverless::Function
Properties:
Handler: app.remove
Policies:
- DynamoDBCrudPolicy:
TableName: !Ref Locations
Events:
ShortenLinkEvent:
Type: Api
Properties:
Path: /remove
Method: post
RestApiId: !Ref ApiGateway
Update:
Type: AWS::Serverless::Function
Properties:
Handler: app.update
Policies:
- DynamoDBCrudPolicy:
TableName: !Ref Locations
Events:
ShortenLinkEvent:
Type: Api
Properties:
Path: /update
Method: post
RestApiId: !Ref ApiGateway
Get:
Type: AWS::Serverless::Function
Properties:
Handler: app.get
Policies:
- DynamoDBReadPolicy:
TableName: !Ref Locations
Events:
ShortenLinkEvent:
Type: Api
Properties:
Path: /get
Method: get
RestApiId: !Ref ApiGateway
ApiGateway:
Type: AWS::Serverless::Api
Properties:
StageName: Prod
EndpointConfiguration:
Type: EDGE
Outputs:
Api:
Value: !Sub "https://${ApiGateway}.execute-api.${AWS::Region}.amazonaws.com/Prod/"
Get:
Value: !Ref Get
Add:
Value: !Ref Add
Remove:
Value: !Ref Remove
Update:
Value: !Ref Update
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment