如何让Lambda的目的地在SAM中工作

时间:2019-12-07 02:47:07

标签: aws-lambda aws-sam

我试图弄清楚如何使用引入here的新目标功能,通过Golang Lambda将数据从一个SQS队列传输到另一个。

设置

在AWS文档之后,我已经构建了以下SAM模板:

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

我有一个简单的golang脚本,它总是成功的:

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)
}

一切都通过AWS SAM部署,报告资源已正确创建。

问题

对于在ToHelloWorldQueue中进行的每个事件,我都希望在1中收到一条以FromHelloWorldQueue作为正文的消息。

通过SQS,我将事件手动放置在ToHelloworld队列中,但是即使消息已正确处理(如CloudWatch所报告),消息也永远不会到达FromHelloworldQueue。我什至尝试为此lambda手动将策略设置为SQS:*,但问题仍然存在。

有人可以帮我弄清楚为什么我做错了吗?

编辑:

编辑1:

当直接调用时,lambda函数实际上将消息发送到FromHelloWorld队列。因此,当lambda由SQS ToHelloWorld队列触发时,这是行不通的。

0 个答案:

没有答案
相关问题