serverless-sam
Version:
Serverless framework plugin to export AWS SAM templates for a service
107 lines (97 loc) • 2.31 kB
YAML
service: serverless-rest-api-with-pynamodb
frameworkVersion: ">=1.1.0 <2.0.0"
plugins:
- serverless-python-requirements
package:
exclude:
- node_modules/**
- .idea/**
- .requirements/**
- env/**
- README.md
- package.json
- package-lock.json
- requirements.txt
provider:
name: aws
runtime: python2.7
region: eu-central-1
environment:
DYNAMODB_TABLE: ${self:service}-${opt:stage, self:provider.stage}
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:Query
- dynamodb:Scan
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:DeleteItem
- dynamodb:DescribeTable
Resource: "arn:aws:dynamodb:${opt:region, self:provider.region}:*:table/${self:provider.environment.DYNAMODB_TABLE}"
functions:
create:
handler: todos/create.create
events:
- http:
path: todos
method: post
cors: true
list:
handler: todos/list.todo_list
events:
- http:
path: todos
method: get
cors: true
get:
handler: todos/get.get
events:
- http:
path: todos/{todo_id}
method: get
cors: true
integration: lambda
request:
paths:
todo_id: true
update:
handler: todos/update.update
events:
- http:
path: todos/{todo_id}
method: put
cors: true
integration: lambda
request:
paths:
todo_id: true
delete:
handler: todos/delete.delete
events:
- http:
path: todos/{todo_id}
method: delete
cors: true
integration: lambda
request:
paths:
todo_id: true
resources:
Resources:
TodosDynamoDbTable:
Type: 'AWS::DynamoDB::Table'
DeletionPolicy: Retain
Properties:
AttributeDefinitions:
-
AttributeName: todo_id
AttributeType: S
KeySchema:
-
AttributeName: todo_id
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
TableName: ${self:provider.environment.DYNAMODB_TABLE}