Skip to content

Latest commit

 

History

History
69 lines (58 loc) · 2 KB

s3.md

File metadata and controls

69 lines (58 loc) · 2 KB

s3 Event type

The s3 event type allows you to handle events generated from the AWS S3 service. The event type is a record-based event type and can contain one or more records. The following is a sample event from the AWS Lambda documentation:

{
    "Records": [
        {
            "eventVersion": "2.0",
            "eventTime": "1970-01-01T00:00:00.000Z",
            "requestParameters": {
                "sourceIPAddress": "127.0.0.1"
            },
            "s3": {
                "configurationId": "testConfigRule",
                "object": {
                    "sequencer": "0A1B2C3D4E5F678901",
                    "key": "HappyFace.jpg"
                },
                "bucket": {
                    "arn": "bucketarn",
                    "name": "sourcebucket",
                    "ownerIdentity": {
                        "principalId": "EXAMPLE"
                    }
                },
                "s3SchemaVersion": "1.0"
            },
            "responseElements": {
                "x-amz-id-2": "EXAMPLE123/5678abcdefghijklambdaisawesome/mnopqrstuvwxyzABCDEFGH",
                "x-amz-request-id": "EXAMPLE123456789"
            },
            "awsRegion": "us-east-1",
            "eventName": "ObjectRemoved:Delete",
            "userIdentity": {
                "principalId": "EXAMPLE"
            },
            "eventSource": "aws:s3"
        }
    ]
}

To map the event using Vandium, we would use the s3() handler:

const vandium = require( 'vandium' );

// handler for an s3 event
exports.handler = vandium.s3( (records, context) => {

        // handle the event
    });

Your handler can return a Promise or value. If you require the use of a callback function for asynchronous operations that cannot be done using Promises, then you can provide a callback parameter in your code.

const vandium = require( 'vandium' );

exports.handler = vandium.s3( (records, context, callback) => {

        // handle the event

        callback( null, 'ok' );
    });