Skip to main content

Scheduled function on AWS

Basic example of AWS Cloud Watch Scheduled Function

This example lives in the pulumi/examples repository. Check out just this directory to use it:

Get started with this example
git clone --filter=blob:none --sparse https://github.com/pulumi/examples pulumi-examples
git -C pulumi-examples sparse-checkout set aws-ts-scheduled-function
cd pulumi-examples/aws-ts-scheduled-function

A simple function in AWS that executes based on a schedule using CloudWatch.

In this example, an S3 Bucket will be created. A function will run every Friday at 11:00pm UTC that will delete all of the objects it contains.

Prerequisites#

  1. Install Pulumi
  2. Configure AWS credentials
  3. Install Node.js

Deploying the example#

  1. Create a new stack:

    Terminal window
    pulumi stack init dev
  2. Set the AWS region:

    Terminal window
    pulumi config set aws:region us-east-1
  3. Install dependencies:

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

    Terminal window
    pulumi up
    Updating (dev):
    Type Name Status
    + pulumi:pulumi:Stack aws-ts-scheduled-function-dev created
    + ├─ aws:cloudwatch:EventRuleEventSubscription emptyTrash created
    + │ ├─ aws:cloudwatch:EventRule emptyTrash created
    + │ ├─ aws:iam:Role emptyTrash created
    + │ ├─ aws:iam:RolePolicyAttachment emptyTrash-32be53a2 created
    + │ ├─ aws:lambda:Function emptyTrash created
    + │ ├─ aws:cloudwatch:EventTarget emptyTrash created
    + │ └─ aws:lambda:Permission emptyTrash created
    + └─ aws:s3:Bucket trash created
    Outputs:
    bucketName: "trash-28693b6"
    Resources:
    + 9 created
    Duration: 16s

Cleaning up#

Once you’re done, destroy the resources and remove the stack:

Terminal window
pulumi destroy
pulumi stack rm

Related

The infrastructure as code platform for any cloud.