early-musician-41645
11/29/2018, 10:12 PMonPut
action in an S3 bucket to trigger a lambda using this code:
// A storage bucket
const bucket = new cloud.Bucket("eshamay-test-bucket");
const bucketName = bucket.bucket.id;
// Trigger a Lamda function when something is added
bucket.onPut("onNewObject", (bucketArgs: any) => {
console.log(`*** New Item in Bucket`);
console.log(bucketArgs);
});
However, I plan to trigger the lambda from multiple buckets and will create/update some DynamoDB items to index the contents of the various bucket objects across multiple regions.
Currently, the lambda above outputs something like this (taken directly from CloudWatch logs:
2018-11-29T12:52:08.159-08:00[onNewObject] { key: 'some/foo/path/myfile.ts', size: 384, eventTime: '2018-11-29T20:52:07.166Z' }
However, my indexing will need to create a couple extra attributes to track region, bucket name, and perhaps some other info of the put
such as the Principle ID, IP address, etc.
I know that S3 events emit something like this:
https://docs.aws.amazon.com/lambda/latest/dg/eventsources.html#eventsources-s3-put
Is there a way to get access to that original event object?
Also, is there a way to create a single lambda to do the DynamoDB update, and then create several buckets across regions that trigger that single lambda onPut
?lemon-spoon-91807
11/29/2018, 10:14 PMearly-musician-41645
11/29/2018, 10:18 PMonObjectCreated
?
I'm assuming the code would be something like
// Create a lambda
// Create the bucket
// Set up the bucket onObjectCreated
// Trigger the lambda somehow from in here using the... lambda.arn?
lemon-spoon-91807
11/29/2018, 10:19 PMearly-musician-41645
11/29/2018, 10:20 PMlemon-spoon-91807
11/29/2018, 10:20 PMonObjectCreated(
name: string, handler: BucketEventHandler,
early-musician-41645
11/29/2018, 10:24 PMevent
pass through as the arg to the handler
? Or, what's the signature for the handler? I'm assuming it takes a single arg.lemon-spoon-91807
11/29/2018, 10:24 PMearly-musician-41645
11/29/2018, 10:27 PMlemon-spoon-91807
11/29/2018, 10:27 PMearly-musician-41645
11/29/2018, 10:28 PMlemon-spoon-91807
11/29/2018, 10:28 PMearly-musician-41645
11/29/2018, 10:29 PMlemon-spoon-91807
11/29/2018, 10:31 PMearly-musician-41645
11/29/2018, 10:33 PM.get
lemon-spoon-91807
11/29/2018, 10:33 PMearly-musician-41645
11/29/2018, 10:34 PMlemon-spoon-91807
11/29/2018, 10:35 PMearly-musician-41645
11/30/2018, 12:12 AM.get
but the buckets I need are in multiple regions. I tried this with no luck:
const bucket = aws.s3.Bucket.get('prod-us-west-1', 'sdp-tsm-prod-eu1-artifacts', { region: 'us-west-1' });
Diagnostics:
aws:s3:Bucket (prod-us-west-1):
error: Preview failed: refreshing urn:pulumi:s3-object-indexer-dev::s3-object-indexer::aws:s3/bucket:Bucket::prod-us-west-1: error reading S3 Bucket (sdp-tsm-prod-eu1-artifacts): BucketRegionError: incorrect region, the bucket is not in 'us-west-2' region
status code: 301, request id: , host id:
config:
aws:region: us-west-2
Not sure how to specify region otherwiselemon-spoon-91807
11/30/2018, 1:35 AMmicroscopic-florist-22719
lemon-spoon-91807
11/30/2018, 1:38 AMmicroscopic-florist-22719
early-musician-41645
11/30/2018, 4:59 AM