Skip to content

Commit

Permalink
feat: switch from serverless -> SAM
Browse files Browse the repository at this point in the history
  • Loading branch information
sammarks committed Jul 22, 2020
1 parent d89c558 commit 257eec9
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 83 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# generated items
packaged-template.yaml
sam-template.yaml
coverage
yarn-error.log

Expand Down
10 changes: 7 additions & 3 deletions deploy-to-s3.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
rm -f ./packaged-template.yaml ./sam-template.yaml
rm -f ./packaged-template.yaml

sls sam export --output ./sam-template.yaml
cp package.json src/package.json
cp yarn.lock src/yarn.lock
cd src
yarn install --production --frozen-lockfile
cd ..

PACKAGE_VERSION=$(node -p -e "require('./package.json').version")

Expand All @@ -20,4 +24,4 @@ aws cloudformation package \
aws s3 cp ./packaged-template.yaml "s3://sammarks-cf-templates-us-east-2/scheduled-tasks/$PACKAGE_VERSION/template.yaml"
aws s3 cp ./packaged-template.yaml "s3://sammarks-cf-templates-us-east-2/scheduled-tasks/template.yaml"

rm -rf ./packaged-template.yaml ./sam-template.yaml
rm -rf ./src/node_modules ./src/package.json ./src/yarn.lock ./packaged-template.yaml
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
"jest": "^26.1.0",
"jest-junit": "^11.0.1",
"lolex": "^6.0.0",
"serverless": "^1.75.1",
"serverless-sam": "^0.2.0",
"standard-version": "^8.0.2"
},
"resolutions": {
Expand Down
117 changes: 117 additions & 0 deletions sam-template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: 'An AWS CloudFormation template for running scheduled tasks.'
Resources:
ingestTopic:
Type: 'AWS::SNS::Topic'
Properties: {}
tasksTable:
Type: 'AWS::DynamoDB::Table'
Properties:
KeySchema:
- AttributeName: taskId
KeyType: HASH
AttributeDefinitions:
- AttributeName: taskId
AttributeType: S
ProvisionedThroughput:
ReadCapacityUnits:
Ref: ReadCapacityUnits
WriteCapacityUnits:
Ref: WriteCapacityUnits
IngestFunction:
Type: 'AWS::Serverless::Function'
Properties:
Handler: src/ingest.handler
Runtime: nodejs10.x
CodeUri: src
MemorySize: 128
Timeout: 3
Policies:
- Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- 'sns:Publish'
Resource:
Ref: DestinationArns
- Effect: Allow
Action:
- 'dynamodb:UpdateItem'
- 'dynamodb:Scan'
- 'dynamodb:DeleteItem'
Resource:
'Fn::GetAtt':
- tasksTable
- Arn
Environment:
Variables:
TASKS_TABLE:
Ref: tasksTable
Events:
Event1:
Type: SNS
Properties:
Topic:
Ref: ingestTopic
ScheduleFunction:
Type: 'AWS::Serverless::Function'
Properties:
Handler: src/schedule.handler
Runtime: nodejs10.x
CodeUri: src
MemorySize: 128
Timeout: 60
Policies:
- Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- 'sns:Publish'
Resource:
Ref: DestinationArns
- Effect: Allow
Action:
- 'dynamodb:UpdateItem'
- 'dynamodb:Scan'
- 'dynamodb:DeleteItem'
Resource:
'Fn::GetAtt':
- tasksTable
- Arn
Environment:
Variables:
TASKS_TABLE:
Ref: tasksTable
Events:
Event1:
Type: Schedule
Properties:
Schedule:
Ref: PollingSchedule
Outputs:
IngestSNSTopicArn:
Description: The ARN of the Ingest SNS topic
Value:
Ref: ingestTopic
Parameters:
PollingSchedule:
Default: rate(5 minutes)
Type: String
Description: >-
The CloudWatch ScheduleExpression defining the interval the polling Lambda
runs at.
ReadCapacityUnits:
Default: 1
Type: Number
Description: The read capacity units for the Scheduled Tasks DynamoDB table.
WriteCapacityUnits:
Default: 1
Type: Number
Description: The write capacity units for the Scheduled Tasks DynamoDB table.
DestinationArns:
Default: ''
Type: CommaDelimitedList
Description: >-
A comma-separated list of possible destination SNS topic ARNs for
permissioning the polling Lambda.
77 changes: 0 additions & 77 deletions serverless.yml

This file was deleted.

0 comments on commit 257eec9

Please sign in to comment.