I want to set values to the fields @requestId
in lambda executions because logs outputted explicitly inside the source code does not contain the @requestId
field value.
I've read an article and tried to output logs like the below but the @requestId did not to be filled.
fmt.Print(`{"requestId":"come on!!"}`)
Neither the below code.
fmt.Print(`{"@requestId":"come on!!"}`)
Are system fields protected?
When an AWS Lambda function is triggered, a context
element is passed to the function.
From AWS Lambda Function Handler in Go - AWS Lambda:
func HandleRequest(ctx context.Context, name MyEvent) (string, error) {
return fmt.Sprintf("Hello %s!", name.Name ), nil
}
From AWS Lambda Context Object in Go - AWS Lambda:
Context Properties
AwsRequestID
– The identifier of the invocation request.
Therefore, you can retrieve the Request ID from the context
. Then, anything that your function prints will be captured in CloudWatch Logs. So, include the Request ID in your print statement.