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.

"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/lambda" "flag" "fmt" "io/ioutil" "os" )

Next, create the session and Lambda client.

aredConfigState: session.SharedConfigEnable, Create Lambda service client

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

Bucket: aws.String(bucketName), Key: aws.String(zipFileName), ObjectVersion: aws.String(""), pFile: contents, ateArgs := &lambda.CreateFunctionInput{ de: createCode, nctionName: aws.String(functionName), ndler: aws.String(handler), le: aws.String(resourceArn), ntime: 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.