Skip to content

Instantly share code, notes, and snippets.

@astrostl
Created November 3, 2016 19:34
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 astrostl/817d4d79161aa5ee4bee4014d3057241 to your computer and use it in GitHub Desktop.
Save astrostl/817d4d79161aa5ee4bee4014d3057241 to your computer and use it in GitHub Desktop.
---
Parameters:
CodeBucket:
Type: String
Resources:
Makesnap3Policy:
Type: "AWS::IAM::ManagedPolicy"
Properties:
PolicyDocument:
Version: "2012-10-17"
Statement:
# DescribeAvailabilityZones allow only needed if you are tagging instances rather than volumes
-
Effect: Allow
Action: "ec2:DescribeAvailabilityZones"
Resource: "*"
-
Effect: Allow
Action:
- "ec2:CreateSnapshot"
- "ec2:CreateTags"
- "ec2:DeleteSnapshot"
- "ec2:DescribeSnapshots"
- "ec2:DescribeInstances"
- "ec2:DescribeTags"
- "ec2:DescribeVolumeAttribute"
- "ec2:DescribeVolumeStatus"
- "ec2:DescribeVolumes"
Resource: "*"
Makesnap3Role:
Type: "AWS::IAM::Role"
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
Effect: Allow
Action: "sts:AssumeRole"
Principal:
Service: "lambda.amazonaws.com"
ManagedPolicyArns:
- !Ref Makesnap3Policy
- "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
Makesnap3Function:
Type: "AWS::Lambda::Function"
Properties:
Code:
S3Bucket: !Ref CodeBucket
S3Key: "makesnap3.zip"
Handler: "makesnap3.lambda_handler"
MemorySize: "128"
Role: !GetAtt Makesnap3Role.Arn
Runtime: "python2.7"
Timeout: "300"
# Makesnap3HourlyRule:
# Type: "AWS::Events::Rule"
# Properties:
# ScheduleExpression: cron(15 */8 * * ? *)"
# Targets:
# -
# Arn: !GetAtt Makesnap3Function.Arn
# Id: "1"
# Input: "{\"period\": \"day\"}"
#
# Makesnap3HourlyPermission:
# Type: "AWS::Lambda::Permission"
# Properties:
# FunctionName: !Ref Makesnap3Function
# Action: "lambda:InvokeFunction"
# Principal: "events.amazonaws.com"
# SourceArn: !GetAtt Makesnap3HourlyRule.Arn
Makesnap3DailyRule:
Type: "AWS::Events::Rule"
Properties:
ScheduleExpression: "cron(30 1 ? * MON-SAT *)"
Targets:
-
Arn: !GetAtt Makesnap3Function.Arn
Id: "1"
Input: "{\"period\": \"day\"}"
Makesnap3DailyPermission:
Type: "AWS::Lambda::Permission"
Properties:
FunctionName: !Ref Makesnap3Function
Action: "lambda:InvokeFunction"
Principal: "events.amazonaws.com"
SourceArn: !GetAtt Makesnap3DailyRule.Arn
Makesnap3WeeklyRule:
Type: "AWS::Events::Rule"
Properties:
ScheduleExpression: "cron(30 2 ? * SUN *)"
Targets:
-
Arn: !GetAtt Makesnap3Function.Arn
Id: "1"
Input: "{\"period\": \"day\"}"
Makesnap3WeeklyPermission:
Type: "AWS::Lambda::Permission"
Properties:
FunctionName: !Ref Makesnap3Function
Action: "lambda:InvokeFunction"
Principal: "events.amazonaws.com"
SourceArn: !GetAtt Makesnap3WeeklyRule.Arn
Makesnap3MonthlyRule:
Type: "AWS::Events::Rule"
Properties:
ScheduleExpression: "cron(30 3 1 * ? *)"
Targets:
-
Arn: !GetAtt Makesnap3Function.Arn
Id: "1"
Input: "{\"period\": \"day\"}"
Makesnap3MonthlyPermission:
Type: "AWS::Lambda::Permission"
Properties:
FunctionName: !Ref Makesnap3Function
Action: "lambda:InvokeFunction"
Principal: "events.amazonaws.com"
SourceArn: !GetAtt Makesnap3MonthlyRule.Arn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment