app.json 2.25 KB
{
  "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" }
    }
  }
}