1. Packages
  2. AWS
  3. How-to Guides
  4. Deploy AWS Synthetics Canary Using a Local Script
AWS v6.60.0 published on Tuesday, Nov 19, 2024 by Pulumi

Deploy AWS Synthetics Canary Using a Local Script

aws logo
AWS v6.60.0 published on Tuesday, Nov 19, 2024 by Pulumi

    View Code Deploy this example with Pulumi

    An example of deploying an AWS Synthetics Canary using a script stored locally.

    This example does the following:

    1. Zips up a colocated canary script.
    2. Pushes the zip file to an S3 bucket.
    3. Creates an IAM role and policy for the canary.
    4. Deploys the canary.

    The canary used in this example is a simple no-op script that writes a message. See Writing Canary Scripts for details regarding canary directory structure and naming conventions. There are some prebaked canary scripts for doing things like checking an API or a link that can be found on AWS.

    Deploying and running the program

    1. Create a new stack:

      $ pulumi stack init dev
      
    2. Set the AWS region:

      $ pulumi config set aws:region us-east-1
      
    3. Restore NPM modules via npm install or yarn install.

      npm install
      
    4. Run pulumi up to preview and deploy changes:

      $ pulumi up
      Previewing update (dev)
      ...
      
      Updating (dev)
      View Live: https://app.pulumi.com/acmecorp/aws-synthetics-canary/dev/updates/1
      
          Type                      Name                       Status
      +   pulumi:pulumi:Stack       aws-synthetics-canary-dev  created
      +   ├─ aws:s3:BucketV2        canary-results             created
      +   ├─ aws:s3:BucketV2        canary-scripts             created
      +   ├─ aws:iam:Role           canary-exec-role           created
      +   ├─ aws:iam:RolePolicy     canary-exec-policy         created
      +   ├─ aws:s3:BucketObjectv2  canary-simple-canary       created
      +   └─ aws:synthetics:Canary  canary-simple              created
      
      Outputs:
          canaryName   : "canary-simple-a4a3974"
          canaryNameArn: "arn:aws:synthetics:us-east-1:052848974346:canary:canary-simple-a4a3974"
      

    Clean up

    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.

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

    aws logo
    AWS v6.60.0 published on Tuesday, Nov 19, 2024 by Pulumi