I've got an AWS step function that invokes a lambda function written in Golang. For some reason it looks like the lambda function is not able to read the input to the step function.
The lambda function -
package main
import (
"fmt"
"github.com/aws/aws-lambda-go/lambda"
)
type InEvent struct {
Name string `json:"name"`
}
type OutEvent struct {
Greeting string `json:"greeting"`
}
func HandleRequest(name InEvent) (OutEvent, error) {
var result OutEvent
result.Greeting = fmt.Sprintf("Hello %s!", name.Name)
return result, nil
}
func main() {
lambda.Start(HandleRequest)
}
The step function -
{
"Comment": "A Hello World example of the Amazon States Language using Pass states",
"StartAt": "Invoke Lambda function",
"States": {
"Invoke Lambda function": {
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"Parameters": {
"FunctionName": "arn:aws:lambda:us-west-1:301438421794:function:SF1_1:$LATEST",
"Payload": {
"Input.$": "$"
}
},
"End": true
}
}
}
Input to the step function -
{
"name": "ABCDE"
}
Output of the step function -
{
"ExecutedVersion": "$LATEST",
"Payload": {
"greeting": "Hello !"
},
"SdkHttpMetadata": {
"AllHttpHeaders": {
"X-Amz-Executed-Version": [
"$LATEST"
],
"x-amzn-Remapped-Content-Length": [
"0"
],
"Connection": [
"keep-alive"
],
"x-amzn-RequestId": [
"5f297331-8b1a-49a0-9ad9-17a78ec1cfd0"
],
"Content-Length": [
"22"
],
"Date": [
"Fri, 25 Dec 2020 19:58:20 GMT"
],
"X-Amzn-Trace-Id": [
"root=1-5fe6445c-5cb6860d2559230940506a2f;sampled=0"
],
"Content-Type": [
"application/json"
]
},
"HttpHeaders": {
"Connection": "keep-alive",
"Content-Length": "22",
"Content-Type": "application/json",
"Date": "Fri, 25 Dec 2020 19:58:20 GMT",
"X-Amz-Executed-Version": "$LATEST",
"x-amzn-Remapped-Content-Length": "0",
"x-amzn-RequestId": "5f297331-8b1a-49a0-9ad9-17a78ec1cfd0",
"X-Amzn-Trace-Id": "root=1-5fe6445c-5cb6860d2559230940506a2f;sampled=0"
},
"HttpStatusCode": 200
},
"SdkResponseMetadata": {
"RequestId": "5f297331-8b1a-49a0-9ad9-17a78ec1cfd0"
},
"StatusCode": 200
}
I expect Output.Payload.greeting to be "Hello ABCDE!" but instead Output.Payload.greeting is "Hello !"
What went wrong here? Why is the name variable in the lambda function not storing the input correctly? Why does "ABCDE" turn into an empty string within the lambda function?
When I directly test the lambda function on the lambda console without using step functions, everything works fine.