-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsst.config.ts
98 lines (93 loc) · 2.85 KB
/
sst.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/// <reference path="./.sst/platform/config.d.ts" />
import * as pulumi from '@pulumi/pulumi';
import { join } from 'path';
import { cwd } from 'process';
import type { AppInput } from './.sst/platform/src/config';
const createCanaryStorage = () => {
const canaryBucket = new aws.s3.Bucket('CanaryBucket', {
versioning: {
enabled: true,
},
forceDestroy: true,
});
const file = new pulumi.asset.FileAsset(join(cwd(), 'canary', 'index.js'));
const canaryCodeArchive = new pulumi.asset.AssetArchive({ 'nodejs/node_modules/index.js': file });
const canaryCodeS3Object = new aws.s3.BucketObject('CanaryCode', {
bucket: canaryBucket.bucket,
key: 'canary.zip',
source: canaryCodeArchive,
});
return { canaryBucket, canaryCodeS3Object };
};
const createCanaryRole = () => {
const canaryRole = new aws.iam.Role('CanaryRole', {
assumeRolePolicy: JSON.stringify({
Version: '2012-10-17',
Statement: [
{
Action: 'sts:AssumeRole',
Principal: {
Service: 'synthetics.amazonaws.com',
},
Effect: 'Allow',
Sid: '',
},
{
Action: 'sts:AssumeRole',
Principal: {
Service: 'lambda.amazonaws.com',
},
Effect: 'Allow',
Sid: '',
},
],
}),
});
new aws.iam.RolePolicyAttachment('S3PolicyAttachment', {
role: canaryRole,
policyArn: 'arn:aws:iam::aws:policy/AmazonS3FullAccess',
});
new aws.iam.RolePolicyAttachment('CWPolicyAttachment', {
role: canaryRole,
policyArn: 'arn:aws:iam::aws:policy/CloudWatchFullAccess',
});
return { canaryRole };
};
export default $config({
app(_input: AppInput) {
return {
name: 'cloudwatch-synthetics-visual-regression-tests',
removal: 'remove',
home: 'aws',
};
},
async run() {
new sst.aws.Astro('Web').url.apply((url) => {
const { canaryBucket, canaryCodeS3Object } = createCanaryStorage();
const { canaryRole } = createCanaryRole();
new aws.synthetics.Canary('ScreenshotCanary', {
name: 'visual-regressions',
artifactS3Location: $interpolate`s3://${canaryBucket.bucket}/`,
executionRoleArn: canaryRole.arn,
handler: 'index.handler',
// https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Library_nodejs_puppeteer.html
runtimeVersion: 'syn-nodejs-puppeteer-7.0',
schedule: {
expression: 'rate(1 hour)',
durationInSeconds: 60,
},
failureRetentionPeriod: 7,
successRetentionPeriod: 7,
startCanary: true,
s3Bucket: canaryBucket.bucket,
s3Key: canaryCodeS3Object.key,
s3Version: canaryCodeS3Object.versionId,
runConfig: {
environmentVariables: {
SITE_URL: url,
},
},
});
});
},
});