Amazon cloudformation Cloudformation API GW集成响应/响应头

Amazon cloudformation Cloudformation API GW集成响应/响应头,amazon-cloudformation,aws-api-gateway,Amazon Cloudformation,Aws Api Gateway,这是可以使用的!参考要在响应参数内使用的S3存储桶。例如: 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.A

这是可以使用的!参考要在响应参数内使用的S3存储桶。例如:

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
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'"

所以本质上我使用的是一个资源AWS::S3::Bucket,它允许模板创建Bucket。因此,名称将是动态的。我希望能够!参考原点内的S3Bucket。这可能吗?我知道它可以像

一样是静态的,一种方法是使用函数如下所示:

这是可以使用的!参考要在响应参数内使用的S3存储桶。例如:

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
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返回值:

Hmm可能我必须转义它,但它实际上并没有给我需要的变量。它给了我访问控制允许来源“{S3Bucket}@mcgoosh抱歉。我的错误。应该是:!Sub'https://${S3Bucket}.s3-${AWS::Region}.amazonaws.com'@mcgoosh此表单更短:!子'https://${S3Bucket.DomainName}'