Skip to content

Instantly share code, notes, and snippets.

@chapimenge3
Created December 4, 2022 18:12
Show Gist options
  • Save chapimenge3/828053ce3622f09590015e0eeab32631 to your computer and use it in GitHub Desktop.
Save chapimenge3/828053ce3622f09590015e0eeab32631 to your computer and use it in GitHub Desktop.
https://blog.chapimenge.com/posts/serverless/todo-api-serverless Todo functions serverless.yml final edition
service: Todo
frameworkVersion: '3'
custom:
tableName: 'todo-table-${self:provider.stage}'
provider:
name: aws
runtime: python3.8
# Totally optional, but it's a good idea to set this
stage: dev
profile: default # if you are working with different AWS account
stackName: todo-stack
logRetentionInDays: 14
region: 'us-east-1' # if you are working with different AWS region choose nearest to you
# defining role for our lambda to access dynamodb
iam:
role:
statements:
- Effect: Allow
Action:
- dynamodb:Query
- dynamodb:Scan
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:DeleteItem
Resource:
- Fn::GetAtt: [ TodoTable, Arn ]
environment:
TODO_TABLE: ${self:custom.tableName}
functions:
# new
createTodo:
handler: handler.create_todo
events:
- httpApi:
path: /create
method: post
listTodos:
handler: handler.list_todo
events:
- httpApi:
path: /list
method: get
updateTodo:
handler: handler.update_todo
events:
- httpApi:
path: /update
method: put
deleteTodo:
handler: handler.delete_todo
events:
- httpApi:
path: /delete
method: delete
resources:
Resources:
TodoTable:
Type: AWS::DynamoDB::Table
Properties:
AttributeDefinitions:
- AttributeName: todoId
AttributeType: S
KeySchema:
- AttributeName: todoId
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
TableName: ${self:custom.tableName}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment