Skip to content

Instantly share code, notes, and snippets.

@moea
Created February 6, 2017 22:42
Show Gist options
  • Save moea/9378ede9773b064087752c699ff16f77 to your computer and use it in GitHub Desktop.
Save moea/9378ede9773b064087752c699ff16f77 to your computer and use it in GitHub Desktop.
service: aws-polling-task-scheduler
provider:
name: aws
runtime: nodejs4.3
environment:
RATE: 300
TASK_TABLE: ${self:service}-${opt:stage, self:provider.stage}-tasks
TOKEN_INDEX: ${self:service}-${opt:stage, self:provider.stage}-tasks-by-token
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:Query
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:DeleteItem
Resource: "arn:aws:dynamodb:${self:provider.region}:*:table/${env:TASK_TABLE}"
- Effect: Allow
Action:
- dynamodb:Query
Resource: "arn:aws:dynamodb:${self:provider.region}:*:table/${env:TASK_TABLE}/*"
functions:
poll-scheduled:
cljs: aws-polling-task-scheduler.handlers/poll-scheduled
events:
- schedule: rate(${env:RATE} seconds)
schedule:
cljs: aws-polling-task-scheduler.handlers/schedule
events:
- http:
path: schedule
method: post
plugins:
- serverless-cljs-plugin
resources:
Resources:
TaskTable:
Type: 'AWS::DynamoDB::Table'
Properties:
TableName: ${env:TASK_TABLE}
AttributeDefinitions:
-
AttributeName: next
AttributeType: N
-
AttributeName: token
AttributeType: S
KeySchema:
-
AttributeName: next
KeySchema: HASH
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
GlobalSecondaryIndexes:
- IndexName: ${env:TOKEN_INDEX}
KeySchema:
-
AttributeName: token
KeySchema: HASH
Projection:
ProjectionType: ALL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment