Skip to content

Instantly share code, notes, and snippets.

@gburgett
Created November 20, 2022 18:45
Show Gist options
  • Save gburgett/d486255b21d736d78ac671da4bfce19c to your computer and use it in GitHub Desktop.
Save gburgett/d486255b21d736d78ac671da4bfce19c to your computer and use it in GitHub Desktop.
Serverless config for AWS Lambda ruby fn with DynamoDB and SES
service: wcc-x
frameworkVersion: '3'
provider:
name: aws
region: us-east-1
runtime: ruby2.7
memorySize: 256
timeout: 10
environment:
stage: ${sls:stage}
region: ${self:provider.region}
service: ${self:service}
tableName: ${self:custom.tableName}
API_KEY: ${env:API_KEY, ''}
DEFAULT_RECIPIENT: ${self:custom.env.DEFAULT_RECIPIENT.${sls:stage, 'dev'}}
logRetentionInDays: 30
tags:
Application: ${self:service}
Stage: ${sls:stage}
iam:
role:
statements:
- Effect: Allow
Action:
- dynamodb:GetItem
- dynamodb:BatchGetItem
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:BatchWriteItem
- dynamodb:Query
- dynamodb:Scan
Resource:
- !GetAtt Table.Arn
- Effect: Allow
Resource: "*"
Action:
- ses:SendEmail
- ses:SendRawEmail
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
functions:
cron:
handler: src/handlers/x/cron.run
events:
- schedule: rate(15 minutes)
resources:
Resources:
Table:
Type: AWS::DynamoDB::Table
Properties:
TableName: ${self:custom.tableName}
Tags:
- Key: Application
Value: ${self:service}
- Key: Stage
Value: ${sls:stage}
BillingMode: PAY_PER_REQUEST
AttributeDefinitions:
- AttributeName: index_name
AttributeType: S
- AttributeName: search
AttributeType: S
KeySchema:
- AttributeName: index_name
KeyType: HASH
- AttributeName: search
KeyType: RANGE
TimeToLiveSpecification:
Enabled: true
AttributeName: 'expires_at'
plugins:
- serverless-ruby-layer
- serverless-export-env
- serverless-plugin-aws-alerts
custom:
tableName: ${self:service}-${sls:stage}
rubyLayer:
include_functions:
- cron
alerts:
stages:
- production
topics:
alarm:
topic: ${self:service}-${sls:stage}-alerts-alarm
notifications:
- protocol: email
endpoint: xxx@me.org
alarms:
- functionErrors
- functionThrottles
env:
REPORTER:
production: 'email'
DEFAULT_RECIPIENT:
dev: ${env:DEFAULT_RECIPIENT, ''}
production: ${env:DEFAULT_RECIPIENT, 'xxx@me.org'}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment