Last active
May 18, 2024 04:54
-
-
Save em-shea/fd6753816ef855f0844216833b389cd6 to your computer and use it in GitHub Desktop.
An example SAM template that creates a DynamoDB table, a Lambda function that writes to DynamoDB, and an EventBridge trigger
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
AWSTemplateFormatVersion: '2010-09-09' | |
Transform: 'AWS::Serverless-2016-10-31' | |
Description: An app that includes a DynamoDB table, a Lambda function that writes to DynamoDB, and a scheduled EventBridge event | |
Resources: | |
LambdaWriteToDynamoDB: | |
# A function that writes to a DynamoDB table on a schedule | |
Type: 'AWS::Serverless::Function' | |
Properties: | |
FunctionName: LambdaWriteToDynamoDB | |
Handler: LambdaWriteToDynamoDB.lambda_handler | |
Runtime: python3.7 | |
CodeUri: ./LambdaWriteToDynamoDB | |
Description: A function that writes to a DynamoDB table on a schedule | |
MemorySize: 128 | |
Timeout: 120 | |
Policies: | |
# Read more about SAM policy templates here | |
# https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-policy-templates.html | |
- DynamoDBCrudPolicy: | |
TableName: !Ref DynamoDBTable | |
Environment: | |
Variables: | |
TABLE_NAME: !Ref DynamoDBTable | |
Events: | |
ScheduledEvent: | |
Type: Schedule | |
Properties: | |
# Read more about schedule expressions here: | |
# https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-create-rule-schedule.html | |
# This event runs every Friday at 16 UTC/9AM PST | |
Schedule: cron(0 16 ? * FRI *) | |
DynamoDBTable: | |
Type: AWS::DynamoDB::Table | |
DeletionPolicy: Retain | |
Properties: | |
TableName: DynamoDBTable | |
AttributeDefinitions: | |
- AttributeName: ListId | |
AttributeType: S | |
- AttributeName: Date | |
AttributeType: S | |
KeySchema: | |
- AttributeName: ListId | |
KeyType: HASH | |
- AttributeName: Date | |
KeyType: RANGE | |
BillingMode: PAY_PER_REQUEST | |
ProvisionedThroughput: | |
ReadCapacityUnits: 0 | |
WriteCapacityUnits: 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thx this helped me setting up my DynamoDB table :)