Can I make an Amazon AWS Lamda function which is triggered by the creation of an S3 bucket?

-1

1

I would like to send a mail when a new bucket is created on our AWS account. I'd prefer this to be near-instantaneous so preferably not time scheduled, but triggered by the CreatBucket event directly.

When I try to create a new function and configure an S3 trigger, the bucket selection is mandatory

G-.

Posted 2017-06-15T15:43:56.710

Reputation: 683

Question was closed 2017-06-20T09:59:26.757

Your question is off-topic here, please read description of [tag:amazon-web-services] – Máté Juhász – 2017-06-16T08:10:27.227

Can you suggest where might be more appropriate? I have received a helpful reply below and similar questions around around similar vmware functionality appear to be allowable on the site – G-. – 2017-06-19T07:48:11.107

Answers

2

EDIT

As @michael-sqlbot has pointed out in the comments, what you are trying to achieve may be possible but with a multi-step process. CloudTrail can log S3 bucket-level events (https://docs.aws.amazon.com/AmazonS3/latest/dev/cloudtrail-logging.html) including bucket creation, it can then be configured to generate CloudWatch events, and finally you can use specific CloudWatch events as triggers for Lambda.


This isn't directly supported, here is the list of all events that can be generated by S3:

  • s3:ObjectCreated:*
  • s3:ObjectCreated:Put
  • s3:ObjectCreated:Post
  • s3:ObjectCreated:Copy
  • s3:ObjectCreated:CompleteMultipartUpload

Amazon S3 APIs such as PUT, POST, and COPY can create an object. Using these event types, you can enable notification when an object is created using a specific API, or you can use the s3:ObjectCreated:* event type to request notification regardless of the API that was used to create an object.

You will not receive event notifications from failed operations.

  • s3:ObjectRemoved:*
  • s3:ObjectRemoved:Delete
  • s3:ObjectRemoved:DeleteMarkerCreated

By using the ObjectRemoved event types, you can enable notification when an object or a batch of objects is removed from a bucket.

You can request notification when an object is deleted or a versioned object is permanently deleted by using the s3:ObjectRemoved:Delete event type. Or you can request notification when a delete marker is created for a versioned object by using s3:ObjectRemoved:DeleteMarkerCreated. For information about deleting versioned objects, see Deleting Object Versions. You can also use a wildcard s3:ObjectRemoved:* to request notification anytime an object is deleted.

You will not receive event notifications from automatic deletes from lifecycle policies or from failed operations.

  • s3:ReducedRedundancyLostObject

You can use this event type to request Amazon S3 to send a notification message when Amazon S3 detects that an object of the RRS storage class is lost.

All events work at an object level, requiring the bucket exist.

Source: https://docs.aws.amazon.com/AmazonS3/latest/dev/NotificationHowTo.html#supported-notification-event-types.

roryrjb

Posted 2017-06-15T15:43:56.710

Reputation: 136

1While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – Donald Duck – 2017-06-15T16:21:05.903

@DonaldDuck I've updated the answer with more detail. – roryrjb – 2017-06-15T16:48:32.277

1

Is this your final answer? AWS CloudTrail can capture S3 bucket creation API calls: https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-supported-services.html#cloudtrail-supported-services-storage-and-content-delivery

– Michael - sqlbot – 2017-06-16T03:36:33.963

1@Michael-sqlbot thanks for pointing this out. I have updated my answer. – roryrjb – 2017-06-16T08:09:17.043

I'm reviewing that doc this morning, it looks like it may be exactly what I need – G-. – 2017-06-16T08:32:34.090

This works SNS to send a quick and dirty email and could be tided up to generate an email in node.js. This will do the job. Thanks – G-. – 2017-06-19T16:26:07.680