amazon-web-services - 如何在无服务器中使用 Sub 函数和 GetAtt?

标签 amazon-web-services aws-cloudformation serverless-framework

考虑以下代码:

EventRule:
  Type: AWS::Events::Rule
  Properties:
    Description: "ny trigger"
    ScheduleExpression: "rate(1 minute)"
    State: "DISABLED"
    Targets:
      -
        Arn: !GetAtt MyFunctionLambdaFunction.Arn
        Id: "someId"
        Input:
          Fn::Sub:
            - '{"arn":"#{arn}"}'
            - arn: !GetAtt MyStateMachine.Arn

这给了我一个错误:

Error: The CloudFormation template is invalid: Template error: One or more Fn::Sub 
intrinsic functions don't specify expected arguments. Specify a string as first argument,
and an optional second argument to specify a mapping of values to replace in the string

最佳答案

此处的 Sub 中不需要 GetAttSub 可以解析诸如 MyStateMachine.Arn 之类的内容。所以你可以这样做:

Input: !Sub 
  - |-
    { "arn": "${MyStateMachine.Arn}" }

在某些情况下,您可能仍然需要传入参数(例如,当您需要调用 ImportValue 等函数时)。例如,如果您的状态机在不同的堆栈中定义并通过 other-stack-MyStateMachine-Arn 输出导出,您可以执行以下操作:

Input: !Sub 
  - |-
    { "arn": "${MyStateMachineArn}" }
  - MyStateMachineArn: !ImportValue 
      'Fn::Sub': 'other-stack-MyStateMachine-Arn'

关于amazon-web-services - 如何在无服务器中使用 Sub 函数和 GetAtt?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57906573/

相关文章:

amazon-web-services - “GetObject 时发生错误。S3 错误代码 : PermanentRedirect. S3 错误消息:存储桶位于此区域:us-east-1

amazon-web-services - 在 Cloudformation 的 SSM Parameter Store 中创建 JSON 值

python - Oauth2 到 aws lambda 上的 google people api

node.js - AWS Lambda 可以访问 S/FTP 或与之交互吗?

linux - 在写入触发的 AWS ec2 上运行同步脚本

c# - .Net Core (2.1) - Lambda 函数可以工作,而在 2.2 中却不行?

amazon-web-services - 使用 AWS Lambda 函数写入 Kinesis 流

amazon-web-services - AWS 数据管道 : Tez fails on simple HiveActivity

aws-cloudformation - Cloudformation 使用引擎 aurora-postgresql 和 enginemode : serverless 创建 RDS 集群

testing - 是否可以使用无服务器框架将测试事件推送到 AWS Lambda?