【问题标题】:Cloudformation API GW IntegrationResponse/response headersCloudformation API GW 集成响应/响应标头
【发布时间】:2020-05-30 06:31:30
【问题描述】:

可以使用 !Ref 到 S3 存储桶以在 ResponseParameter 中使用。例如:

IntegrationResponses:
      - ResponseParameters:
          method.response.header.Access-Control-Allow-Headers: "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'"
          method.response.header.Access-Control-Allow-Methods: "'POST,OPTIONS'"
          method.response.header.Access-Control-Allow-Origin: "'https://dynamicbucketname.s3-us-west-2.amazonaws.com'"
          method.response.header.Access-Control-Allow-Credentials: "'true'"

S3Bucket:
 Type: AWS::S3::Bucket
 Properties:
   PublicAccessBlockConfiguration:
     BlockPublicAcls: true
     IgnorePublicAcls: false
     BlockPublicPolicy: true
     RestrictPublicBuckets: true  
   WebsiteConfiguration:
     IndexDocument: index.html
     ErrorDocument: error.html

所以基本上我使用的是资源 AWS::S3::Bucket,它允许模板创建存储桶。因此,名称将是动态的。我希望能够 !Ref S3Bucket 在 Origin 内。这甚至可能吗?我知道它可以是静态的,例如 "'https://www.example.com'"

【问题讨论】:

    标签: amazon-cloudformation aws-api-gateway


    【解决方案1】:

    一种方法是使用Sub函数如下:

    可以使用 !Ref 到 S3 存储桶以在 ResponseParameter 中使用。例如:

    IntegrationResponses:
          - ResponseParameters:
              method.response.header.Access-Control-Allow-Headers: "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'"
              method.response.header.Access-Control-Allow-Methods: "'POST,OPTIONS'"
              method.response.header.Access-Control-Allow-Origin: !Sub "'https://${S3Bucket.DomainName}'"
              method.response.header.Access-Control-Allow-Credentials: "'true'"
    

    DomainName 之外的其他Bucket 返回值在here 中列出:

    【讨论】:

    • 嗯,也许我必须逃避它,但它实际上并没有给我我需要的变量。它给了我 Access-Control-Allow-Origin '{S3Bucket}'
    • @mcgoosh 对不起。我的错。应该是:!Sub "'https://${S3Bucket}.s3-${AWS::Region}.amazonaws.com'"
    • @mcgoosh 这个表格更短:!Sub "'https://${S3Bucket.DomainName}'"
    猜你喜欢
    • 1970-01-01
    • 2019-07-05
    • 1970-01-01
    • 1970-01-01
    • 2018-12-02
    • 2020-04-18
    • 2018-06-19
    • 1970-01-01
    • 2018-06-09
    相关资源
    最近更新 更多