27
loading...
This website collects cookies to deliver better user experience
cp canary-function.js ./nodejs/node_modules/
zip -r sourcecode.zip ./nodejs/*
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: 'Service'
Parameters:
- ServiceName
- CanaryName
- AlertEmail
- Label:
default: 'Buckets'
Parameters:
- CanarySourceCodeBucketName
- CanarySourceCodeKey
- CanaryArtifactBucketName
ParameterLabels:
ServiceName:
default: Service Name
CanaryName:
default: Canary Name
AlertEmail:
default: Email
CanarySourceCodeBucketName:
default: Source code bucket name
CanarySourceCodeKey:
default: Key for the object
CanaryArtifactBucketName:
default: The name of the S3 bucket where the artefacts will be store
Parameters:
ServiceName:
Description: Enter a lower case, high level service name without environment details. Used to autofill service names. For example, your-service-name
Type: String
CanaryName:
Description: Enter a lower case name for the canary, as they should be known. For example dave not Dave
Type: String
AlertEmail:
Description: Email address to send staging build alerts to, or example [email protected]
Type: String
CanarySourceCodeBucketName:
Description: S3 Bucket Name where the source code lives
Type: String
CanarySourceCodeKey:
Description: Key of the object which contains the source code
Type: String
CanaryArtifactBucketName:
Description: S3 Bucket Name where the canary saves the screenshots and other
Type: String
CloudwatchCanary:
Type: AWS::Synthetics::Canary
Properties:
ArtifactS3Location: !Sub s3://${CanaryArtifactBucketName}
Code:
Handler: canary-function.handler
S3Bucket: !Sub ${CanarySourceCodeBucketName}
S3Key: !Sub ${CanarySourceCodeKey}
Name: dave-the-canary
RuntimeVersion: syn-nodejs-puppeteer-3.1
Schedule:
Expression: rate(5 minutes)
StartCanaryAfterCreation: true
ExecutionRoleArn: !GetAtt CloudwatchCanaryRole.Arn
CloudwatchCanaryPolicy:
Type: AWS::IAM::Policy
Properties:
PolicyName: !Sub ${ServiceName}-dave-the-canary-policy
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- synthetics:*
Resource: "*"
- Effect: Allow
Action:
- s3:CreateBucket
- s3:PutEncryptionConfiguration
Resource:
- arn:aws:s3:::*
- Effect: Allow
Action:
- iam:ListRoles
- s3:ListAllMyBuckets
- s3:GetBucketLocation
- xray:GetTraceSummaries
- xray:BatchGetTraces
- apigateway:GET
Resource: "*"
- Effect: Allow
Action:
- s3:GetObject
- s3:ListBucket
- s3:PutObject
Resource: arn:aws:s3:::*
- Effect: Allow
Action:
- s3:GetObjectVersion
Resource: arn:aws:s3:::*
- Effect: Allow
Action:
- iam:PassRole
Resource:
- !Sub arn:aws:iam::*:role/service-role/${CloudwatchCanaryRole}
Condition:
StringEquals:
iam:PassedToService:
- lambda.amazonaws.com
- synthetics.amazonaws.com
- Effect: Allow
Action:
- iam:GetRole
Resource:
- !Sub arn:aws:iam::*:role/service-role/*
- Effect: Allow
Action:
- cloudwatch:GetMetricData
- cloudwatch:GetMetricStatistics
Resource: "*"
- Effect: Allow
Action:
- cloudwatch:PutMetricAlarm
- cloudwatch:PutMetricData
- cloudwatch:DeleteAlarms
Resource:
- '*'
- Effect: Allow
Action:
- cloudwatch:DescribeAlarms
Resource:
- arn:aws:cloudwatch:*:*:alarm:*
- Effect: Allow
Action:
- lambda:CreateFunction
- lambda:AddPermission
- lambda:PublishVersion
- lambda:UpdateFunctionConfiguration
- lambda:GetFunctionConfiguration
Resource:
- arn:aws:lambda:*:*:function:cwsyn-*
- Effect: Allow
Action:
- lambda:GetLayerVersion
- lambda:PublishLayerVersion
Resource:
- arn:aws:lambda:*:*:layer:cwsyn-*
- arn:aws:lambda:*:*:layer:Synthetics:*
- Effect: Allow
Action:
- ec2:DescribeVpcs
- ec2:DescribeSubnets
- ec2:DescribeSecurityGroups
Resource:
- "*"
- Effect: Allow
Action:
- sns:ListTopics
Resource:
- "*"
- Effect: Allow
Action:
- sns:CreateTopic
- sns:Subscribe
- sns:ListSubscriptionsByTopic
Resource:
- arn:*:sns:*:*:Synthetics-*
Roles:
- !Ref CloudwatchCanaryRole
CloudwatchCanaryRole:
Type: AWS::IAM::Role
Properties:
RoleName: !Sub ${ServiceName}-${CanaryName}-the-canary-role
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
CloudwatchCanaryAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
ActionsEnabled: true
AlarmDescription: !Sub ${ServiceName}-${CanaryName}-the-canary-alert
ComparisonOperator: LessThanThreshold
EvaluationPeriods: 1
DatapointsToAlarm: 1
MetricName: SuccessPercent
Namespace: CloudWatchSynthetics
Period: 60
Statistic: Average
Threshold: 100
TreatMissingData: notBreaching
AlarmActions:
- !Ref CloudwatchCanaryAlarmTopic
Dimensions:
- Name: CanaryName
Value: !Sub ${CanaryName}-the-canary
CloudwatchCanaryAlarmTopic:
Type: AWS::SNS::Topic
Properties:
DisplayName: !Sub ${CanaryName}-cw-canary-alarms
Subscription:
- Endpoint: !Ref AlertEmail
Protocol: email