amazon-web-services - 使用 Cloud Formation 从 Lambda 获取价值并检查分支的条件
问题描述
我附上了样本,让您清楚地了解我要解决的问题。
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条件处遇到错误。请使用一些示例模板帮助解决这种情况。我也不能在条件块中使用 !GetAtt ,因为我们不应该使用 get 属性。
错误消息 - 在堆栈验证期间
调用 ValidateTemplate 操作时发生错误 (ValidationError):模板错误:Fn::If 需要列表参数,第一个元素是条件
解决方案
您不能像您尝试的那样在 If 中硬编码条件:
Fn::If: [!Equals [!GetAtt IdentifyUserRole.value, true], !GetAtt PORoleId.value, !GetAtt DSRoleId.value]
第一个参数必须是部分Conditions
( docs ) 中的条件:
参考条件部分中的条件。
随后,您不能基于部分GetAtt
或任何其他资源构建条件Resources
。
相同的文档还写道:
您只能从模板的参数和映射部分引用其他条件和值。例如,您可以引用输入参数中的值,但不能引用条件中资源的逻辑 ID。
推荐阅读
- javascript - 检查“选定文本”父级是否有类
- javascript - 我从 localStorage 获得的输入类型文本的值未提交
- c# - 如何通过 ajax 请求在 Controller 中触发 ASP.NET MVC 4 方法
- vulkan - 如何在遵循 vulkan 教程时修复 mac m1 上的 VK_KHR_portability_subset 错误
- python - 如何使用相同的索引细分熊猫数据框
- android - 启用配置缓存会导致构建失败
- django - comment added by the logging in user didn't properly save
- postgresql - Install postgres extension PGXN "fatal error: unistd.h: No such file or directory"
- python - ImportError: libffi.so.6: cannot open shared object file: No such file or directory
- node.js - can a net::ERR_FAILED cause cors 'access-control-allow-origin' errors?