【发布时间】:2022-01-22 02:36:40
【问题描述】:
我需要根据我的 lambda 函数的环境传递不同的变量。在以下条件下创建,但在尝试使用 !If 时出错。感谢有关如何解决此问题的所有帮助和建议。
部署时出错:
Properties validation failed for resource LambdaFunction
YML 文件:
Conditions:
IsProd: !Equals [!Ref AppEnv, "production"]
IsNonProd: !Not [!Equals [!Ref AppEnv, "production"]]
LambdaFunction:
Type: AWS::Lambda::Function
DependsOn:
- LambdaLayer
Properties:
FunctionName: !Sub '${AppName}-${AppEnv}'
Handler: function.handler
Layers:
- !Ref LambdaLayer
VpcConfig:
SecurityGroupIds:
- Ref: SecurityGroup
SubnetIds:
- Ref: PrivateSubnetAz1
- Ref: PrivateSubnetAz2
Code:
S3Bucket: !Sub 'app-deploy-${AWS::AccountId}-${AWS::Region}'
S3Key: !Ref S3LambdaKey
Environment:
Variables:
!If
- "IsNonProd"
-
- DD_SITE: !GetAtt EncryptedDDSite.CipherText
- DD_API_KEY: !GetAtt EncryptedDDApiKey.CipherText
- USER_DEV: !GetAtt EncryptedUserDev.CipherText
- PASS_DEV: !GetAtt EncryptedPassDev.CipherText
- USER_STG: !GetAtt EncryptedUserStg.CipherText
- PASS_STG: !GetAtt EncryptedPassStg.CipherText
- USER_TEST: !GetAtt EncryptedUserTest.CipherText
- PASS_TEST: !GetAtt EncryptedPassTest.CipherText
- AppEnv: !Ref AppEnv
-
- DD_SITE: !GetAtt EncryptedDDSite.CipherText
- DD_API_KEY: !GetAtt EncryptedDDApiKey.CipherText
- USER_PRD: !GetAtt EncryptedUserPrd.CipherText
- PASS_PRD: !GetAtt EncryptedPassPrd.CipherText
- AppEnv: !Ref AppEnv
Runtime: python3.8
MemorySize: 128
Timeout: 300
Role: !GetAtt
- LambdaRole
- Arn
【问题讨论】:
-
你得到哪个错误?
-
Json parsing exception message = Unrecognized token 'AWSTemplateFormatVersion': was expecting ('true', 'false' or 'null') at [ Yaml parsing exception message = while parsing a block mapping in 'reader', line 339, column 9: Variables: ^expected <block end>, but found '<block mapping start>' in 'reader', line 356, column 11: AppEnv: !Ref AppEnv ^ at [ -
模板的 parameters 部分有什么内容?
标签: amazon-web-services amazon-cloudformation