I'm trying to figure out how to use the new destination feature, introduced here, to transfer data from one SQS queue, to another one, through a Golang lambda.
Set up
Following AWS documentation, I have build the following SAM template :
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
helloworld
Resources:
helloworldFunction:
Type: AWS::Serverless::Function
Properties:
Timeout: 30
CodeUri: helloworld/
Handler: helloworld
Runtime: go1.x
Events:
QueueEvent:
Type: SQS
Properties:
Queue: !GetAtt Tohelloworld.Arn
Policies:
- SQSSendMessagePolicy:
QueueName:
!GetAtt Fromhelloworld.QueueName
EventInvokeConfig:
Type: AWS::Lambda::EventInvokeConfig
Properties:
FunctionName: !Ref helloworldFunction
Qualifier: "$LATEST"
MaximumEventAgeInSeconds: 60
MaximumRetryAttempts: 0
DestinationConfig:
OnSuccess:
Destination: !GetAtt Fromhelloworld.Arn
Tohelloworld:
Type: AWS::SQS::Queue
Properties:
VisibilityTimeout: 30
Fromhelloworld:
Type: AWS::SQS::Queue
Properties:
VisibilityTimeout: 30
I have a trivial golang script, that always succeed :
package main
import (
"context"
"fmt"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
)
func handler(ctx context.Context, name events.SQSEvent) (int, error) {
return 1, nil
}
func main() {
lambda.Start(handler)
}
Everything is deployed through AWS SAM, ressources are reported to having been correctly created.
Problem
For each event put in the ToHelloWorldQueue
I was expecting to get a message with 1
as body in the FromHelloWorldQueue
.
Through SQS, I manually put an event in the ToHelloworld
Queue, but the message never reaches the FromHelloworldQueue
, even if the message has been correctly processed (as reported by CloudWatch). I even tried to manually set the policy to SQS:*
for this lambda, but the problem still remains.
Can anyone help figuring out why I'm doing wrong please?
Edit:
Edit 1:
When directly invoked, the lambda function actually sends the message to the FromHelloWorld
queue. So this just does not works when the lambda is triggered by the SQS ToHelloWorld
queue.