Serverless Templates

MD
S
Markdown

Serverless template for creating SQS queues, Lambda Functions and Crons to call the functions

service: marketing

resources: Resources: TaskQueue: Type: AWS::SQS::Queue Properties: QueueName: marketing-${opt:stage,self:provider.stage} VisibilityTimeout: 60 RedrivePolicy: deadLetterTargetArn: {"Fn::GetAtt" : [ "DeadLetterQueue" , "Arn" ]} maxReceiveCount: 3 DeadLetterQueue: Type: AWS::SQS::Queue Properties: QueueName: marketing-${opt:stage,self:provider.stage}-dlx

provider: name: aws runtime: nodejs8.10 stage: develop region: ${file(../../config/variables.yaml):env.server.AWS_REGION} iamRoleStatements: - Effect: Allow Action: - sqs:SendMessage Resource: {"Fn::GetAtt" : [ "TaskQueue" , "Arn" ]} environment: MARKETING_QUEUE_URL: Ref: TaskQueue

package: individually: true exclude: - ./**

functions:

# Add your lambda function here

cron:

handler: app/test.handler # Function to be run

events:

- schedule: rate(5 minutes) # Define when the cron runs

# use rate(Value Unit):

# Every 5 minutes => rate(5 minutes)

# Every hour => rate(1 hour)

# Every seven days => rate(7 days)

# use cron(Minutes Hours Day-of-month Month Day-of-week Year):

# 0:15 AM (UTC) every day => cron(15 10 * * ? *)

# 6:00 PM Monday through Friday => cron(0 18 ? * MON-FRI *)

# 8:00 AM on the first day of the month => cron(0 8 1 * ? *)

# Every 10 min on weekdays => cron(0/10 * ? * MON-FRI *)

# Every 5 minutes between 8:00 AM and 5:55 PM weekdays => cron(0/5 8-17 ? * MON-FRI *)

# 9:00 AM on the first Monday of each month => cron(0 9 ? * 2#1 *)

# Note: One of the day-of-month or day-of-week values must be a question mark (?)

environment: # Define environment variables to be used by the handler

MESSAGE: TEST

new-upvotes: handler: app/cron.handler package: exclude: - ./** include: - app/cron.js events: - schedule: cron(15 10 * * ? *) environment: MESSAGE: NEW_UPVOTES

invitation-reminder: handler: app/cron.handler package: exclude: - ./** include: - app/cron.js events: - schedule: cron(15 10 * * ? *) environment: MESSAGE: INVITATION_REMINDER

invite-friends: handler: app/cron.handler package: include: - app/cron.js events: - schedule: cron(0 10 1 * ? *) environment: MESSAGE: INVITE_FRIENDS

write-post: handler: app/cron.handler package: include: - app/cron.js events: - schedule: cron(0 10 1 * ? *) environment: MESSAGE: WRITE_POST

Created on 8/19/2019