gpt4 book ai didi

string - 在 Cloudformation YAML 中,在多行字符串中使用 Ref (?使用 Fn :Sub)

转载 作者:行者123 更新时间:2023-12-04 04:51:20 27 4
gpt4 key购买 nike

假设您有一个 aws 资源,例如

  Resources:
IdentityPool:
Type: "AWS::Cognito::IdentityPool"
Properties:
IdentityPoolName: ${self:custom.appName}_${self:provider.stage}_identity
CognitoIdentityProviders:
- ClientId:
Ref: UserPoolClient

“AWS::Cognito::IdentityPool”的引用返回此资源的 ID。现在假设我想在多行字符串中引用该 id。我试过了

Outputs:  
AmplifyConfig:
Description: key/values to be passed to Amplify.configure(config);
Value: |
{
'aws_cognito_identity_pool_id': ${Ref: IdentityPool}, ##<------ Error
'aws_sign_in_enabled': 'enable',
'aws_user_pools_mfa_type': 'OFF',
}

我也尝试过使用 Fn:Sub 但没有成功。

   AmplifyConfig:
Description: key/values to be passed to Amplify.configure(config);
Value:
Fn::Sub
- |
{
'aws_cognito_identity_pool_id': '${Var1Name}',
'aws_sign_in_enabled': 'enable',
}
- Var1Name:
Ref: IdentityPool

有办法做到这一点吗?

最佳答案

在 YAML 中使用管道符号 | 将以下所有缩进行转换为多行字符串。

管道与 !Sub 结合可以让您使用:

  • 您的资源 Ref 可以像 ${YourResource} 一样轻松返回值
  • 他们的 Fn::GetAtt 返回仅带有句点的值 ${YourResource.TheAttribute}
  • 任何伪参数,就像 ${AWS:region}

就像 !Sub | 一样简单,跳到下一行并添加适当的缩进。示例:

Resources:
YourUserPool:
Type: AWS::Cognito::UserPool
Properties:
UserPoolName: blabla

Outputs:
AmplifyConfig:
Description: key/values to be passed to Amplify.configure(config);
Value: !Sub |
{
'aws_cognito_identity_pool_id': '${YourUserPool}',
'aws_sign_in_enabled': 'enable',
'aws_user_pools_mfa_type': 'OFF',
}
AdvancedUsage:
Description: use Pseudo Parameters and/or resources attributes
Value: !Sub |
{
'aws_region': '${AWS::Region}',
'user_pool_arn': '${YourUserPool.Arn}',
}

关于string - 在 Cloudformation YAML 中,在多行字符串中使用 Ref (?使用 Fn :Sub),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50070155/

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