Lambda Functions Part 3

Allegedly we’ve laid the groundwork, let’s dive in and see if we can create the Lambda function that will work with S3 containers, as described in the last post. From the CLI, this is a simple matter of executing the following:

$ aws lambda create-function --region us-east-1 --function-name CreateThumbnail --zip-file fileb://textTN.zip --role arn:aws:iam::485603662400:role/lambda_s3_exec_role --handler CreateThumbnail.handler --runtime nodejs --timeout 10 --memory-size 1024

I’ve left out the fact that the initial ARN was unsuccessful, as alluded to last time. I’ve also left out the implied step of zipping up the *js code we edited to suit our bucket names, along with the dependencies. Here, this is the file textTN.zip on my local filesystem. At the time of writing, these steps are detailed here.

A successful execution will return output that should look something like:

{
"FunctionName": "CreateThumbnail",
"CodeSize": 120360,
"MemorySize": 1024,
"FunctionArn": "arn:aws:lambda:us-east-1:48560xxxxxxx:function:CreateThumbnail",
"Handler": "CreateThumbnail.handler",
...
}

Indeed a look at the AWS Lambda console confirms the creation of the new function. Eventually I’ll hook up real event data from S3 in order to trigger the execution, for now I’ll used some canned input. In preparation, I upload an input image HappyFace.png to the input bucket, and create/edit and input.txt file thusly:

{
"Records":[
{
"eventVersion":"2.0",
"eventSource":"aws:s3",
"awsRegion":"us-east-1",
"eventTime":"1970-01-01T00:00:00.000Z",
"eventName":"ObjectCreated:Put",
"userIdentity":{
"principalId":"AKIAJDCAKH2FEYQTKHAA"
},
"requestParameters":{
"sourceIPAddress":"127.0.0.1"
},
"responseElements":{
"x-amz-request-id":"C3D13FE58DE4C810",
"x-amz-id-2":"FMyUVURIY8/IgAtTv8xRjskZQpcIZ9KG4V5Wp6S7S/JRWeUWerMUE5JgHvANOjpD"
},
"s3":{
"s3SchemaVersion":"1.0",
"configurationId":"testConfigRule",
"bucket":{
"name":"BUCKET_NAME_IN",
"ownerIdentity":{
"principalId":"AKIAJDCAKH2FEYQTKHAA"
},
"arn":"arn:aws:s3:::BUCKET_NAME_IN"
},
"object":{
"key":"HappyFace.png",
"size":1024,
"eTag":"d41d8cd98f00b204e9800998ecf8427e",
"versionId":"096fKKXTRTtl3on89fVO.nfljtsv6qko"
}}}]
}

Pay particular attention to the input bucket name, as well as the key for the object you want to operate on. Next time; test!