Skip to content

Instantly share code, notes, and snippets.

@alexcasalboni
Created March 5, 2019 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexcasalboni/ca8a51e48da3d574f8fc24a6cb258bda to your computer and use it in GitHub Desktop.
Save alexcasalboni/ca8a51e48da3d574f8fc24a6cb258bda to your computer and use it in GitHub Desktop.
AWS Lambda for Amazon DynamoDB daily resize (CloudFormation template)
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Parameters:
TablePrefix:
Type: String
Resources:
TableDailyResize:
Type: AWS::Serverless::Function
Properties:
Handler: handler.daily_resize
Policies:
- AWSLambdaExecute # Managed Policy
- Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- dynamodb:CreateTable
- dynamodb:UpdateTable
Resource: !Sub 'arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${TablePrefix}*'
Runtime: python2.7
Timeout: 30
MemorySize: 256
Environment:
Variables:
TABLE_NAME: !Ref TablePrefix
Events:
CreateNewTableEveryDay:
Type: Schedule
Properties:
Input: '{"Operation": "create_new"}'
Schedule: cron(45 23 * * ? *) # every day at 11.45PM
ResizeYesterdaysTableEveryDay:
Type: Schedule
Properties:
Input: '{"Operation": "resize_old"}'
Schedule: cron(15 0 * * ? *) # every day at 00.15AM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment