amazon-web-services - AWS:在多个无服务器应用程序中重用 amazon Cognito Userpool
问题描述
我已将无服务器项目分成多个项目,以避免模板错误资源 > 200。现在我面临另一个错误。
我已经使用 AWS cognito 实现了身份验证和授权,它适用于一个无服务器应用程序中的 lambda 函数。我正在尝试在另一个无服务器项目中重新使用相同的 Cognito 用户池来授权 API。但是,每个无服务器项目都会在 Cognito 中再次创建具有相同名称的 UserPool。如何避免这个问题。
这是我的 serverless.yml 和虚拟响应在 lambda 函数中的样子
CognitoUserPool:
Type: "AWS::Cognito::UserPool"
Properties:
MfaConfiguration: OFF
UserPoolName: userpool-impl
#RequiredAttributes:
# - email
UsernameAttributes:
- email
Policies:
PasswordPolicy:
MinimumLength: 8
RequireLowercase: True
RequireNumbers: True
RequireSymbols: True
RequireUppercase: True
CognitoUserPoolClient:
Type: "AWS::Cognito::UserPoolClient"
Properties:
ClientName: client-impl
GenerateSecret: False
UserPoolId:
Ref: CognitoUserPool
ApiGatewayAuthorizer:
DependsOn:
- ApiGatewayRestApi
Type: AWS::ApiGateway::Authorizer
Properties:
Name: cognito-authorizer
IdentitySource: method.request.header.Authorization
RestApiId:
Ref: ApiGatewayRestApi
Type: COGNITO_USER_POOLS
ProviderARNs:
- Fn::GetAtt: [CognitoUserPool, Arn]
拉姆达函数:
response = {
"statusCode": 200,
'headers': {
"Access-Control-Allow-Origin": "http://localhost:3000",
"Access-Control-Allow-Credentials": True
},
"body": "Dummy Response"
}
解决方案
推荐阅读
- swift - ImagePicker 确认视图对齐
- javascript - 如何使用管道从复选框列表中过滤Angular 7中的对象数组
- laravel - 无法在 Bitnami LAMP 堆栈上使用 Cron 运行 PHP Artisan 命令
- angular - 以不同的角度分量显示数据
- java - 当分配的值给出 NumberFormatException 错误时,如何防止向量扩展?
- javascript - 如何根据 OPCODE (discord.js) 分离捕获的错误
- java - KeyPressed不同图像视图的卷积问题,例如锐化
- python - 如何登录页面并打印课程
- amazon-web-services - 允许在 AWS 上托管的多租户 SaaS 平台上的租户自定义域名
- linux - 单行脚本中的未知信号错误