forked from pulumi/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/bin/ | ||
/node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
name: aws-ts-scheduled-function | ||
runtime: nodejs | ||
description: A minimal AWS TypeScript Pulumi program |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "aws-typescript", | ||
"devDependencies": { | ||
"@types/node": "latest" | ||
}, | ||
"dependencies": { | ||
"@pulumi/pulumi": "latest", | ||
"@pulumi/aws": "latest", | ||
"@pulumi/awsx": "latest" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"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" | ||
] | ||
} |