Skip to content

Instantly share code, notes, and snippets.

@ahawkins
Created May 12, 2016 18:51
Show Gist options
  • Save ahawkins/e1f150777fcd1b802109b079f1ad225a to your computer and use it in GitHub Desktop.
Save ahawkins/e1f150777fcd1b802109b079f1ad225a to your computer and use it in GitHub Desktop.
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Lambdas to collect KPIs and scheduled event source",
"Parameters": {
"S3Bucket": {
"Type": "String",
"Description": "S3 bucket for lambda artifacts"
},
"S3Key": {
"Type": "String",
"Description": "S3 key for lambds zip"
}
},
"Resources": {
"CollectPageViewKPIs": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Handler": "collect_page_views.handler",
"Role": { "Fn::GetAtt" : [ "LambdaExecutionRole", "Arn" ] },
"Code": {
"S3Bucket": { "Ref": "S3Bucket" },
"S3Key": { "Ref": "S3Key" }
},
"Runtime": "nodejs4.3",
"Timeout": "25"
}
},
"ScrapeKPIsRule": {
"Type": "AWS::Events::Rule",
"Properties": {
"Description": "ScheduledRule",
"ScheduleExpression": "rate(10 minutes)",
"State": "ENABLED",
"Targets": [
{
"Arn": { "Fn::GetAtt": [ "CollectPageViewKPIs", "Arn" ] },
"Id": "CollectPageViews"
}
]
}
},
"PermissionToCollectPageViewKPIs": {
"Type": "AWS::Lambda::Permission",
"Properties": {
"FunctionName": { "Ref": "CollectPageViewKPIs" },
"Action": "lambda:InvokeFunction",
"Principal": "events.amazonaws.com",
"SourceArn": { "Fn::GetAtt": [ "ScrapeKPIsRule", "Arn" ] }
}
},
"LambdaExecutionRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Principal": {
"Service": [ "lambda.amazonaws.com" ]
},
"Action": [ "sts:AssumeRole" ]
}]
},
"Path": "/",
"Policies": [{
"PolicyName": "root",
"PolicyDocument": {
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": [ "logs:*" ],
"Resource": "arn:aws:logs:*:*:*"
}]
}
}]
}
}
},
"Outputs": {
"PageViewCollector": {
"Description": "Lambda ARN",
"Value": { "Ref": "CollectPageViewKPIs" }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment