-
Notifications
You must be signed in to change notification settings - Fork 36
Getting Started
Although not required, we recommand you review AWS Lambda Developer Guide first.
Exercise:
- Create a Hello World Lambda function using the Lambda console.
- Invoke the Lambda function manually using a sample event data.
- Verify execution results and logs created by the Lambda function.
Prerequisites:
- Retrieve SDK.
go get -d github.com/eawsy/aws-lambda-go/...
- Create project.
mkdir hello-world-go
cd hello-world-go
- 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() {}
- Create package.
docker run --rm -v $GOPATH:/go -v $PWD:/tmp eawsy/aws-lambda-go
-
Signin to AWS Management Console.
-
Configure runtime.
- Upload package.
- Configure access.
- Leave the default advanced settings values, and confirm the Lambda function creation.
-
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.
- Save and test. AWS Lambda executes your function on your behalf. The handler in your Lambda function receives and processes the sample event.
Copyright 2016 Alsanium, SAS. or its affiliates. All rights reserved.
Source code licensed under the Apache License, Version 2.0.
Documentation licensed under the Creative Commons Attribution 4.0 International Public License.
[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)