Skip to content

Commit

Permalink
Mitchgerdisch/canary add bucketversioning (pulumi#1207)
Browse files Browse the repository at this point in the history
* working on stuff

* working version

* fix linting errors
  • Loading branch information
MitchellGerdisch committed Apr 22, 2022
1 parent 3245f1f commit 61ad2c8
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 22 deletions.
2 changes: 2 additions & 0 deletions aws-ts-synthetics-canary/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,6 @@ There are some prebaked canary scripts for doing things like checking an API or

1. Run `pulumi destroy` to tear down all resources.

NOTE: Until https://github.com/hashicorp/terraform-provider-aws/issues/19288 is addressed, the Canary's lambda function and related layers are left after the stack is destroyed. So you will want to manually clean up these items.

1. To delete the stack itself, run `pulumi stack rm`. Note that this command deletes all deployment history from the Pulumi Console.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 30 additions & 20 deletions aws-ts-synthetics-canary/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import { generateCanaryPolicy } from "./canaryPolicy";
// Used for naming convention
const baseName = "canary";

// Bucket for storing canary scripts
const canaryScriptsBucket = new aws.s3.BucketV2(`${baseName}-scripts`);
// Bucket for storing canary results
// Bucket for storing canary RESULTS
const canaryResultsS3Bucket = new aws.s3.BucketV2(`${baseName}-results`, {
// This allows the bucket to be destroyed even if it contains canary results.
forceDestroy: true,
Expand Down Expand Up @@ -39,24 +37,36 @@ const canaryExecutionPolicy = new aws.iam.RolePolicy(`${baseName}-exec-policy`,
policy: canaryResultsS3Bucket.arn.apply(arn => generateCanaryPolicy(arn)),
});

// zip up, upload and deploy the "simple canary"
const simpleCanaryScriptArchive = new pulumi.asset.FileArchive("./canaries/simple-canary/");
const simpleCanaryScriptObject = new aws.s3.BucketObjectv2(`${baseName}-simple-canary`, {
// Bucket for storing the canary SCRIPTS
const canaryScriptsBucket = new aws.s3.BucketV2(`${baseName}-scripts`);
// Enable versioning so that as new scripts are uploaded the canary will be updated as well.
const canaryScriptBucketVersioning = new aws.s3.BucketVersioningV2(`${baseName}-scripts-versioning`, {
bucket: canaryScriptsBucket.id,
source: simpleCanaryScriptArchive,
versioningConfiguration: {
status: "Enabled",
},
});
const simpleCanary = new aws.synthetics.Canary(`${baseName}-simple`, {
artifactS3Location: pulumi.interpolate`s3:https://${canaryResultsS3Bucket.id}`,
executionRoleArn: canaryExecutionRole.arn,
handler: "exports.handler",
runtimeVersion: "syn-nodejs-puppeteer-3.5",
schedule: {
expression: "rate(1 minute)",
},
s3Bucket: canaryScriptsBucket.id,
s3Key: simpleCanaryScriptObject.id,
startCanary: true,
// zip up, upload and deploy the "simple canary"
const canaryScriptArchive = new pulumi.asset.FileArchive("./canaries/simple-canary/");
const canaryScriptObject = new aws.s3.BucketObjectv2(`${baseName}-script`, {
bucket: canaryScriptBucketVersioning.bucket,
source: canaryScriptArchive,
});

// Create the canary.
const canary = new aws.synthetics.Canary(`${baseName}-simple`, {
artifactS3Location: pulumi.interpolate`s3:https://${canaryResultsS3Bucket.id}`,
executionRoleArn: canaryExecutionRole.arn,
handler: "exports.handler",
runtimeVersion: "syn-nodejs-puppeteer-3.5",
schedule: {
expression: "rate(1 minute)",
},
s3Bucket: canaryScriptsBucket.id,
s3Key: canaryScriptObject.id,
s3Version: canaryScriptObject.versionId,
startCanary: true,
});

export const canaryName = simpleCanary.name;
export const canaryNameArn = simpleCanary.arn;
export const simpleCanaryName = canary.name;
export const simpleCanaryArn = canary.arn;
2 changes: 2 additions & 0 deletions aws-ts-synthetics-canary/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
},
"dependencies": {
"@pulumi/aws": "^5.0.0",
"@pulumi/aws-native": "^0.15.0",
"@pulumi/command": "^0.1.0",
"@pulumi/pulumi": "^3.0.0"
}
}

0 comments on commit 61ad2c8

Please sign in to comment.