gpt4 book ai didi

amazon-web-services - 使用 Cloud Formation 从 Lambda 获取值(value)并检查分支条件

转载 作者:行者123 更新时间:2023-12-03 07:35:04 25 4
gpt4 key购买 nike

我附上了示例,以便让您清楚地了解我正在尝试解决的问题。

AWSTemplateFormatVersion: '2010-09-09'
Description: Project Service Catalog get lambda data

Parameters:
Environment:
Type: String
Description: Environment of the SageMaker

ProjectId:
Type: String
Description: Project ID of the SageMaker

SsmRoleLambdaArn:
Type: AWS::SSM::Parameter::Value<String>
Default: '/data-science/role-lambda/arn'
Description: Arn to lookup Role of the Session using project id

Resource:
IdentifyUserRole:
Type: Custom::GetParam
Properties:
ServiceToken: !Ref SsmRoleLambdaArn
pl_role: !Sub '${Environment}-sso-data-science-${ProjectId}-pl-role'
ds_role: !Sub '${Environment}-sso-data-science-${ProjectId}-ds-role'

KmsKey:
Type: AWS::KMS::Key
Properties:
Description: !Sub 'Encryption for ${Environment}-${ProjectId}-${Prid}-${NotebookInstanceNameSuffix}'
EnableKeyRotation: true
Tags:
- Key: Environment
Value: !Ref Environment
- Key: Owner
Value: !Ref Owner
- Key: ProjectId
Value: !Ref ProjectId
- Key: PrincipalId
Value: !Sub
- "${RoleId}:${Prid}"
- RoleId:
Fn::If: [!Equals [!GetAtt IdentifyUserRole.value, true], !GetAtt PORoleId.value, !GetAtt DSRoleId.value]

我在 PrincipalID 标记中的 IF 条件处收到错误。请使用一些示例模板帮助解决此情况。我也无法在 Conditions block 中使用 !GetAtt,因为我们不应该使用 get 属性。

错误消息 - 堆栈验证期间

An error occurred (ValidationError) when calling the ValidateTemplate operation: Template error: Fn::If requires a list argument with the first element being a condition

最佳答案

您无法像您尝试的那样对 If 中的条件进行硬编码:

 Fn::If: [!Equals [!GetAtt IdentifyUserRole.value, true], !GetAtt PORoleId.value, !GetAtt DSRoleId.value]

第一个参数必须是条件部分中的条件 (docs):

reference to a condition in the Conditions section.

随后,您将无法基于 GetAttResources 部分中的任何其他资源构造条件。

相同的文档还写道:

You can only reference other conditions and values from the Parameters and Mappings sections of a template. For example, you can reference a value from an input parameter, but you cannot reference the logical ID of a resource in a condition.

关于amazon-web-services - 使用 Cloud Formation 从 Lambda 获取值(value)并检查分支条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63287388/

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