yaml - AWS SAM lambda 目标

标签 yaml aws-cloudformation aws-serverless

我是 AWS 无服务器架构的新手。我想使用 lambda 做一些事情,然后将结果发送到 SQS。我想使用 SAM 来实现这一点 - 希望它能够构建资源(SQS、Lambda 函数)而无需手动执行。该代码与 this 非常相似.

我想在 .yml 中定义所有资源。运行 sam deploy 命令后,它创建了 SQS 和 Lambda 函数。创建 SQS 后,我将更新 Lambda 代码,以便它可以使用正确的 SQS URL 发送数据。不过,我想看看是否可以自动化整个过程(无需填写新创建的 SQS 的 URL)。

  1. sam deploy 命令可能会在第一次创建队列,然后将 URL 直接提供给 lambda。
  2. 当我进入 AWS lambda 控制台时,我可以看到已部署的 lambda 函数。但是我看不到 SQS 被定义为 lambda 函数的目标。

提前致谢。

最佳答案

您可以一次性连接所有内容。

Is it possible that the sam deploy command would create the Queue the first time and then it would feed the URL directly to lambda?

是的。 SAM/CloudFormation 使用Intrinsic Functions在模板中为运行时才可用的属性分配值。 AWS::SQS::Queue资源exposes several such properties 。在引用的模板中,例如QueuePublisherFunction接收队列 URL 作为环境变量:

Environment:
  Variables:
    SQSqueueName: !Ref MySqsQueue # When you pass the logical ID of this resource to the intrinsic Ref function, Ref returns the queue URL.

When I went to AWS lambda console, I could see the deployed lambda function. However I couldn't see that the SQS is defined as the destination of the lambda function.

这是预期的。如果您遵循模板,则您的 Lambda 未配置 Destination ,其中有 special meaning in Lambda-speak (例如,可选地用于错误处理)。

您可以在哪里查看队列如何连接到 Lambda?您的队列应该在 QueueConsumerFunction 中可见。 Lambda 控制台作为“触发器”。您的QueueConsumerFunction应在 SQS 控制台中作为“Lambda 触发器”可见。您的QueuePublisherFunction不与基础设施级别的队列耦合。它只是将消息放入队列中。

关于yaml - AWS SAM lambda 目标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72626968/

相关文章:

aws-api-gateway - 无法使用云形成将 VPC_LINK 与 Api 网关上的方法集成映射

amazon-web-services - 如何使用 CommaDelimitedList 参数创建资源 ARNS 列表?

amazon-web-services - AWS CloudFormation 配置... UserData 与 Ansible 之类的?

amazon-web-services - 具有 Cloudformation 的 AWS 无服务器 API 的阶段 "dev already exists"

amazon-web-services - 在 Serverless 框架中创建 lambda 后可以创建资源吗?

maven - Github Action用Maven构建jar并用于Docker镜像构建

go - 使用键解析 yaml 提供错误

azure - 在 k8s 部署上下文中,Azure 管道 yaml 中的 `maxReplicas` 属性意味着什么?

node.js - AWS CloudFormation 与 node.js 10.x 更新错误 "ZipFile can only be used when Runtime is set to <older node.js versions>"

yaml - 在线提供 RAML 示例