-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.js
69 lines (55 loc) · 1.8 KB
/
deploy.js
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
const shell = require('shelljs');
const stackName = process.env.STACK_NAME || 'imaginarium';
const s3FunctionBucket = process.env.S3_FUNCTION_BUCKET;
const s3ImageBucket = process.env.S3_IMAGE_BUCKET;
const region = process.env.AWS_REGION;
if (!stackName) {
console.error('Please provide STACK_NAME environment variable');
process.exit(1);
}
if (!s3FunctionBucket) {
console.error('Please provide S3_FUNCTION_BUCKET environment variable');
process.exit(1);
}
if (!s3ImageBucket) {
console.error('Please provide S3_IMAGE_BUCKET environment variable');
process.exit(1);
}
if (!region) {
console.error('Please provide AWS_REGION environment variable');
console.error('So we know where to deploy this stack');
process.exit(1);
}
shell.exec('yarn install --force');
// now build
shell.exec('node build.js');
// now package lambda
shell.exec(
`aws cloudformation package --template-file cloudformation.yaml --s3-bucket ${s3FunctionBucket} --output-template-file dist/template.yml`,
);
const parameterOverrides = [
`S3FunctionBucket=${s3FunctionBucket}`,
`S3ImageBucket=${s3ImageBucket}`,
];
if (process.env.CDN_CERTIFICATE_ARN) {
parameterOverrides.push(
`CDNCertificateArn=${process.env.CDN_CERTIFICATE_ARN}`,
);
}
if (process.env.CDN_ALIASES) {
parameterOverrides.push(`CDNAliases=${process.env.CDN_ALIASES}`);
}
if (process.env.S3_IMAGE_KEY_PATTERN) {
parameterOverrides.push(
`S3ImageKeyPattern=${process.env.S3_IMAGE_KEY_PATTERN}`,
);
}
if (process.env.SERVICENAME) {
parameterOverrides.push(`SERVICENAME=${process.env.SERVICENAME}`);
}
// now deploy lambda
shell.exec(
`aws --region ${region} cloudformation deploy --template-file dist/template.yml --stack-name ${stackName} --parameter-overrides ${parameterOverrides.join(
' ',
)} --capabilities CAPABILITY_NAMED_IAM`,
);