AWS SDK for Go
Developer Guide

Creating a Lambda Function

The following example creates the Lambda function functionName in the us-west-2 region using the following values:

  • Role ARN: resourceArn. In most cases, you need to attach only the AWSLambdaExecute managed policy to the policy for this role.

  • Function entry point: handler

  • Runtime: runtime

  • Zip file: zipFileName + .zip

  • Bucket: bucketName

  • Key: zipFileName

The first step is to import the packages we use in the example.

"" "" "" "flag" "fmt" "io/ioutil" "os" )

Next, create the session and Lambda client.

SharedConfigState: session.SharedConfigEnable, })) // Create Lambda service client

Next, create the structures for the input argument to the CreateFunction function.

S3Bucket: aws.String(bucketName), S3Key: aws.String(zipFileName), S3ObjectVersion: aws.String(""), ZipFile: contents, } createArgs := &lambda.CreateFunctionInput{ Code: createCode, FunctionName: aws.String(functionName), Handler: aws.String(handler), Role: aws.String(resourceArn), Runtime: aws.String(runtime), }

Finally, call CreateFunction and display a message with the result of the call.

if err != nil { fmt.Println("Cannot create function: " + err.Error()) } else { fmt.Println(result) } }

See the complete example on GitHub.