使用 Import 和 sub psudo 函数 return 错误

Using Import and sub psudo function return error

我有以下 cloudformation 代码:

  usagePlan:
Type: AWS::ApiGateway::UsagePlan
Properties:
  ApiStages:
  - ApiId: !ImportValue: "test-restApi-lambda-send-email-contactus-post"
    Stage: "stg1"
  Description: Customer ABC's usage plan
  Quota:
    Limit: 5000
    Period: MONTH
  Throttle:
    BurstLimit: 200
    RateLimit: 100
  UsagePlanName: Plan_ABC

一切正常,代码正常运行。 一旦我把它变成:

  usagePlan:
Type: AWS::ApiGateway::UsagePlan
Properties:
  ApiStages:
  - ApiId:
    Fn::ImportValue: !Sub "${project}-restApi-lambda-send-email-contactus-post"
    Stage: "stg1"
  Description: Customer ABC's usage plan
  Quota:
    Limit: 5000
    Period: MONTH
  Throttle:
    BurstLimit: 200
    RateLimit: 100
  UsagePlanName: Plan_ABC

我收到以下错误:

An error occurred (ValidationError) when calling the CreateStack operation: [/Resources/usagePlan/Type/ApiStages/0/ApiId] 'null' values are not allowed in templates

问题正好发生在这个阶段:

Fn::ImportValue: !Sub "${project}-restApi-lambda-send-email-contactus-post"

有什么想法吗?这是 aws 中的错误吗?

您缺少 Fn::ImportValue 之前的标签:

这应该有效:

ApiStages:
  - ApiId:
      Fn::ImportValue: !Sub "${project}-restApi-lambda-send-email-contactus-post"