Skip to content
This repository has been archived by the owner on Jan 14, 2020. It is now read-only.

Getting Started

Farzad Senart edited this page Nov 1, 2016 · 1 revision

Although not required, we recommand you review AWS Lambda Developer Guide first.

Exercise:

  1. Create a Hello World Lambda function using the Lambda console.
  2. Invoke the Lambda function manually using a sample event data.
  3. Verify execution results and logs created by the Lambda function.

Prerequisites:

  1. Setup Go Environment.
  2. Setup Docker Engine.
  3. Setup AWS Account.
  4. Setup AWS CLI.

Create a Hello World Lambda function

  1. Retrieve SDK.
go get -d github.com/eawsy/aws-lambda-go/...
  1. Create project.
mkdir hello-world-go
cd hello-world-go
  1. Create handler.
package main

import (
  "encoding/json"
  "log"

  "github.com/eawsy/aws-lambda-go/service/lambda/runtime"
)

func handle(evt json.RawMessage, ctx *runtime.Context) (interface{}, error) {
  // log.Printf("Received event: %s\n", string(evt))
  var values map[string]string
  json.Unmarshal(evt, &values)
  log.Printf("value1 = %s\n", values["key1"])
  log.Printf("value2 = %s\n", values["key2"])
  log.Printf("value3 = %s\n", values["key3"])
  return values["key1"], nil // Echo back the first key value
  // return nil, errors.New("Something went wrong")
}

func init() {
  runtime.HandleFunc(handle)
}

func main() {}
  1. Create package.
docker run --rm -v $GOPATH:/go -v $PWD:/tmp eawsy/aws-lambda-go
  1. Signin to AWS Management Console.

  2. Go to Lambda > New function > Configure function.

  3. Configure runtime.

HelloWorld - Configure runtime

  1. Upload package.

HelloWorld - Upload package

  1. Configure access.

HelloWorld - Configure access

  1. Leave the default advanced settings values, and confirm the Lambda function creation.

HelloWorld - Create function

Invoke the Lambda function manually

  1. Go to Lambda > Functions > hello-world-go.

  2. Open the Configure test event modal from the Actions list. The following sample event template appears in the window.

{
  "key3": "value3",
  "key2": "value2",
  "key1": "value1"
}

You can change key and values in the sample JSON, but don't change the event structure. If you do change any keys and values, you must update the sample code accordingly.

  1. Save and test. AWS Lambda executes your function on your behalf. The handler in your Lambda function receives and processes the sample event.

Verify execution results and logs

HelloWorld - Execution results

Welcome

[Getting Started](Getting Started)

  • [Create](Getting Started#create-a-hello-world-lambda-function)
  • [Invoke](Getting Started#invoke-the-lambda-function-manually)
  • [Verify](Getting Started#verify-execution-results-and-logs)

[Programming Model](Programming Model)

  • [Handler](Programming Model#handler)
  • [Context](Programming Model#context)
  • [Logging](Programming Model#logging)
  • [Errors](Programming Model#errors)

[Deployment Package](Deployment Package)

  • [Project](Deployment Package#project)
  • [Package](Deployment Package#package)

Contact

Clone this wiki locally