首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >没有硬编码值的openapi中定义的认知用户池授权器

没有硬编码值的openapi中定义的认知用户池授权器
EN

Stack Overflow用户
提问于 2021-08-26 16:51:48
回答 1查看 313关注 0票数 0

我有一个API网关Rest资源定义了这个模板:

代码语言:javascript
运行
AI代码解释
复制
AWSTemplateFormatVersion: '2010-09-09'
Description: "Api gateway"
Resources:
  ApiGateway:
    Type: "AWS::ApiGateway::RestApi"
    Properties:
      BodyS3Location: "./openapi-spec.yaml"

openapi-spec.yaml (基于此示例)的内容是:

代码语言:javascript
运行
AI代码解释
复制
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了吗?

注意:已经尝试使用阶段变量,但它们在这里似乎不起作用。

EN

回答 1

Stack Overflow用户

发布于 2022-04-19 01:09:28

如果您没有现有的认知用户池,那么您必须使用AWS::Cognito::UserPool在CloudFormation中定义一个用户池,那么您可以使用!GetAtt简单地引用这个用户池的arn。

但是,如果您有一个现有的认知用户池,那么您也可以使用CloudFormation将其导入到这些步骤之后的堆栈中。

下面是一个例子:

template.yaml

代码语言:javascript
运行
AI代码解释
复制
Resources:
  ApiGateway:
    Type: "AWS::ApiGateway::RestApi"
    Properties:
      BodyS3Location: "./openapi-spec.yaml"

  CognitoUserPool:
    Type: AWS::Cognito::UserPool
    Properties:
      # ....

openapi-spec.yaml

代码语言:javascript
运行
AI代码解释
复制
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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68946836

复制
相关文章

相似问题

领券
社区富文本编辑器全新改版!诚邀体验~
全新交互,全新视觉,新增快捷键、悬浮工具栏、高亮块等功能并同时优化现有功能,全面提升创作效率和体验
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档