我有一个API网关Rest资源定义了这个模板:
AWSTemplateFormatVersion: '2010-09-09'
Description: "Api gateway"
Resources:
ApiGateway:
Type: "AWS::ApiGateway::RestApi"
Properties:
BodyS3Location: "./openapi-spec.yaml"
openapi-spec.yaml
(基于此示例)的内容是:
openapi: "3.0.2"
info:
title: SampleApi
paths:
/test:
get:
summary: Test
responses:
"200":
description: Ok
security:
- UserPool: [ ]
x-amazon-apigateway-integration:
# ....
components:
securitySchemes:
UserPool:
type: apiKey
name: Authorization
in: header
x-amazon-apigateway-authtype: cognito_user_pools
x-amazon-apigateway-authorizer:
type: cognito_user_pools
providerARNs:
### THIS VALUE ###
- "arn:aws:cognito-idp:eu-west-1:123456789012:userpool/eu-west-1_abcd12345"
我希望能够在多个环境/帐户中部署这个模板,使用这个硬编码的providerARN限制了这一点。所以我的问题是:
如何动态地传递providerARNs
字段的值?
如果不能这样做,那么有什么解决办法吗?这样我就不必在这里硬编码providerArns了吗?
注意:已经尝试使用阶段变量,但它们在这里似乎不起作用。
发布于 2022-04-19 01:09:28
如果您没有现有的认知用户池,那么您必须使用AWS::Cognito::UserPool
在CloudFormation中定义一个用户池,那么您可以使用!GetAtt
简单地引用这个用户池的arn。
但是,如果您有一个现有的认知用户池,那么您也可以使用CloudFormation将其导入到这些步骤之后的堆栈中。
下面是一个例子:
template.yaml
Resources:
ApiGateway:
Type: "AWS::ApiGateway::RestApi"
Properties:
BodyS3Location: "./openapi-spec.yaml"
CognitoUserPool:
Type: AWS::Cognito::UserPool
Properties:
# ....
openapi-spec.yaml
openapi: "3.0.2"
# ....
components:
securitySchemes:
UserPool:
type: apiKey
name: Authorization
in: header
x-amazon-apigateway-authtype: cognito_user_pools
x-amazon-apigateway-authorizer:
type: cognito_user_pools
providerARNs:
- !GetAtt CognitoUserPool.Arn
https://stackoverflow.com/questions/68946836
复制相似问题