adding scheduled functions example
ADD
aws-ts-scheduled-function/.gitignore
+/bin/
+/node_modules/

ADD
aws-ts-scheduled-function/Pulumi.yaml
+name: aws-ts-scheduled-function
+runtime: nodejs
+description: A minimal AWS TypeScript Pulumi program

ADD
aws-ts-scheduled-function/index.ts
+import * as aws from "@pulumi/aws";
+
+// Create an AWS resource (S3 Bucket)
+const trashBucket = new aws.s3.Bucket("trash");
+
+// A handler function that will list objects in the bucket and bulk delete them
+const emptyTrash: aws.cloudwatch.EventRuleEventHandler = async (
+ event: aws.cloudwatch.EventRuleEvent
+) => {
+ const s3Client = new aws.sdk.S3();
+ const bucket = trashBucket.id.get();
+
+ const { Contents = [] } = await s3Client
+ .listObjects({ Bucket: bucket })
+ .promise();
+ const objects = Contents.map(object => {
+ return { Key: object.Key };
+ });
+
+ await s3Client
+ .deleteObjects({
+ Bucket: bucket,
+ Delete: { Objects: objects, Quiet: false }
+ })
+ .promise();
+};
+
+// Schedule the function to run every Friday at 11:00pm UTC (6:00pm EST)
+// More info on Schedule Expressions at https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html
+const emptyTrashSchedule: aws.cloudwatch.EventRuleEventSubscription = aws.cloudwatch.onSchedule(
+ "emptyTrash",
+ "cron(0 23 ? * FRI *)",
+ emptyTrash
+);
+
+// Export the name of the bucket
+export const bucketName = trashBucket.id;

ADD
aws-ts-scheduled-function/package.json
+{
+ "name": "aws-typescript",
+ "devDependencies": {
+ "@types/node": "latest"
+ },
+ "dependencies": {
+ "@pulumi/pulumi": "latest",
+ "@pulumi/aws": "latest",
+ "@pulumi/awsx": "latest"
+ }
+}

ADD
aws-ts-scheduled-function/tsconfig.json
+{
+ "compilerOptions": {
+ "outDir": "bin",
+ "target": "es6",
+ "lib": [
+ "es6"
+ ],
+ "module": "commonjs",
+ "moduleResolution": "node",
+ "sourceMap": true,
+ "experimentalDecorators": true,
+ "pretty": true,
+ "noFallthroughCasesInSwitch": true,
+ "noImplicitAny": true,
+ "noImplicitReturns": true,
+ "forceConsistentCasingInFileNames": true,
+ "strictNullChecks": true
+ },
+ "files": [
+ "index.ts"
+ ]
+}

adding scheduled functions example