CategoriesAWSGolang

Convert Go Code to AWS Lambda function

Import lambda package by running go get -u github.com/aws/aws-lambda-go/lambda. Make the handler available for remote procedure call by AWS lambda and utilizing lambda.start method as depicted in the image below:

Building – For Windows 10 users

  1. set GO111MODULE=on
  2. RUN go get -u github.com/aws/aws-lambda-go/cmd/build-lambda-zip
  3. set GOOS=linux
  4. set GOARCH=amd64
  5. set CGO_ENABLED=0
  6. RUN go build -o main main.go
  7. COPY main and PASTE in build-lambda-zip directory
  8. RUN build-lambda-zip.exe -o main.zip main

Assuming that the above steps were followed one should end up with a main.zip file. Browse to AWS lambda from AWS console, create function and upload the new zip file. Make sure that the code does not require any permissions that needs access to other AWS services.

Give it a try

Configure the test events and run a test.

The below shows a successful attempt where “finished” is returned from the code that we built above.