Beginnings in Golang and AWS – Part V – Events, Lambda and Transcribe (cont’d)


In todays post we’ll cover an event handler that our Lambda function is going to use when it receives notification of an MP4 file being dropped in our S3 bucket from a subscribed S3 event. This will in turn cover the Context and Event objects. Lastly, we’ll look at the one specific to our function, S3Event.

Our Code

Because we’re only covering the handler and background info on the same and events, the code within the function is removed for this post.

// Handler is the Lambda function handler
// It uses an S3 event source, with the Lambda function being trigged
// when a CreateObject event occurs on an S3 bucket that has Events configured
func Handler(ctx context.Context, s3Event events.S3Event) {


func main() {


Lambda Function Handlers for Go

For building a Lambda function handler in Go, you have a degree of scope with regards to the input and output parameters you use, provided they conform to, per the latest documentation, the following rules.

  • The handler may take between 0 and 2 arguments. If there are two arguments, the first argument must implement context.Context.
  • The handler may return between 0 and 2 arguments. If there is a single return value, it must implement error. If there are two return values, the second value must implement error.

Although not strictly required for our function, Handler, we are using two parameters. The first, per the requirements of above, will be the implementation of context.Context. The second is the actual event data.

Context Object

The service which calls your Lambda function carries metadata, which the developer may find useful to view, or use. This is where the Context object comes into play. When your function signature contains a parameter for this, information is passed into this. There’s a plethora of information that can be available, some of which are service specific and others standard. An example of one of the latter is the AwsRequestID, a unique identifier that can be used as a reference later should AWS support be required. The complete documentation for the Context object is available here:

Event Data

This is the core information passed from the service to the function. It’s format is completely based on said service. In order to manage this, the Go SDK features interfaces for most event sources. In our case, this is the events.s3Event one.

If you wish to look at it’s construction in more detail, you can find it in the s3.go file, located within the events directory of the aws-lambda-go package.

We’ll be setting up an event subscription so that once an MP4 file is dropped into our S3 bucket, it invokes the Lambda function. What does the typical S3 event data our function would be passed look like? Look below.

Here’s the type of information we could expect to see once we have our Lambda function fully in place and an event subscription created to our S3 bucket. More on the latter later.

    "Records": [
            "eventVersion": "2.0",
            "eventSource": "aws:s3",
            "awsRegion": "eu-west-1",
            "eventTime": "2018-07-10T05:26:14.8Z",
            "eventName": "ObjectCreated:Put",
            "userIdentity": {
                "principalId": ""
            "requestParameters": {
                "sourceIPAddress": "xxxxxxx"
            "responseElements": {
                "x-amz-id-2": "d8RfIrVGqhNSjmtSMkE6BmKHyzuAJBE+eDizEKiO9Jv0NUCwfesfrqYsRptsAdQ+4nZXtR4vRvc=",
                "x-amz-request-id": "706F905A81A24629"
            "s3": {
                "s3SchemaVersion": "1.0",
                "configurationId": "2717c2d4-8189-485d-b7e0-cafe707be54a",
                "bucket": {
                    "name": "xxxxxxxxx",
                    "ownerIdentity": {
                        "principalId": "xxxxxxxx"
                    "arn": "arn:aws:s3:::xxxxxxxxxxxx"
                "object": {
                    "key": "sample.mp4",
                    "size": 5381540,
                    "urlDecodedKey": "",
                    "versionId": "",
                    "eTag": "ca7caf9e588d04ca0fbeee760284ba04",
                    "sequencer": "005B444375F09FE3D9"

There is a lot of information there, but the key part of information passed that we’ll be using is contained within the object section.

In this post, we’ve covered the basics of a Lambda event handler for Go, the valid signatures that can be used with it and their purpose. We’ve also looked at the typical information that we can expect to be passed into our S3 event.

In the next blog, we’ll dig deeper into the function and the code within.

thanks for reading! Feedback always welcome. 🙂




Leave a Reply

Your email address will not be published. Required fields are marked *