gpt4 book ai didi

amazon-web-services - 带有 cloudformation 输出变量的 Serverless.yml 自定义堆栈

转载 作者:行者123 更新时间:2023-12-04 21:04:09 26 4
gpt4 key购买 nike

我是无服务器的新手,如果这是非常基本的,请原谅我。我在创建 AMAZON COGNITO POOL 时遇到了一个问题,我想将此 userPoolId 使用到我的自定义堆栈块中以将其与 appsync 连接。下面是我的 serverless.yml

 custom:
accountId: 123xxxxxxxx
appSync:
apiId: 123xyzxxxxxxx # only required for update-appsync
authenticationType: AMAZON_COGNITO_USER_POOLS
userPoolConfig:
awsRegion: ap-southeast-1
defaultAction: ALLOW
userPoolId: (here it only takes string but i want to reference)
resources:
Resources:
# Cognito - User pool
CognitoUserPool:
Type: AWS::Cognito::UserPool
Properties:
UserPoolName: abc_xyz_pool
# Cognito - Client
CognitoUserPoolClient:
Type: AWS::Cognito::UserPoolClient
Properties:
ClientName: abc_xyz_pool
GenerateSecret: false
UserPoolId:
Ref: CognitoUserPool
# Cognito - Identity
CognitoIdentityPool:
Type: AWS::Cognito::IdentityPool
Properties:
IdentityPoolName: sc_identity_pool
AllowUnauthenticatedIdentities: false
CognitoIdentityProviders:
- ClientId:
Ref: CognitoUserPoolClient
ProviderName:
Fn::GetAtt: [CognitoUserPool, ProviderName]

我可以在 Resources 块内引用,但不能在自定义块内引用它

最佳答案

serverless.yml 中的自定义块在创建资源之前进行评估,因此无法引用这些输出。即使在 CFN 中,对于引用它们的位置和方式也存在限制。

但是,您可以引用来自其他 CloudFormation 堆栈的输出。

您应该将无服务器项目拆分为两个项目,第一个建立用户池,第二个使用该基础设施。

在您的第一个项目中,您拥有用户池资源,并导出 ID 以备将来在其他堆栈中使用,如下所示:

Resources:
Outputs:
MyUserPoolId:
Value:
Ref: CognitoUserPool # Key name of user pool resource
Export:
Name: MyUserPoolId

在需要池 ID 的第二个项目中,您将导入它:
custom:
appSync:
userPoolConfig:
userPoolId:
Fn::ImportValue: MyUserPoolId

需要为第二个项目部署您的第一个项目以导入导出的值。

您也可以使用 ENV 变量,但这仍然需要您首先建立您的用户池。

关于amazon-web-services - 带有 cloudformation 输出变量的 Serverless.yml 自定义堆栈,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50636166/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com