gpt4 book ai didi

amazon-web-services - CloudFormation模板中的错误到底在哪里?

转载 作者:行者123 更新时间:2023-12-03 07:30:58 24 4
gpt4 key购买 nike

我面临的事实是我的 CloudFormation 模板大于 51200 字节。所以我决定把这个主模板分成几个模板。当我尝试构建堆栈时,收到错误消息,指出嵌套模板中的资源属性不正确。

问题:

嵌套模板是否可能看不到主模板中声明的参数值?

错误:

Invalid template resource property 'CreateWidgetRole'

template.yaml(片段):

AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Parameters:
EnvironmentName:
Type: String
SettingsServiceStackName:
Type: String
S3Bucket:
Type: String
Conditions:
IsProductionEnvironment:
'Fn::Equals':
- Ref: EnvironmentName
- Prod
Resources:
SettingsServiceResources:
'Fn::Transform':
Name: 'AWS::Include'
Parameters:
Location:
'Fn::Sub': >-
s3://${S3Bucket}/included_templates/settings_service_resources_template.yaml

settings_service_resources_template.yaml:

CreateWidgetRole:
Type: 'AWS::IAM::Role'
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service: appsync.amazonaws.com
Action: 'sts:AssumeRole'
Policies:
- PolicyName: CreateWidgetFunctionAccess
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action: 'lambda:InvokeFunction'
Resource:
'Fn::ImportValue':
'Fn::Sub': >-
${EnvironmentName}${SettingsServiceStackName}:${EnvironmentName}CreateWidgetARN
CreateWidgetDataSource:
Type: 'AWS::AppSync::DataSource'
Properties:
ApiId:
'Fn::GetAtt': GraphQLApi.ApiId
Name:
'Fn::Sub': '${EnvironmentName}CreateWidget'
Type: AWS_LAMBDA
LambdaConfig:
LambdaFunctionArn:
'Fn::ImportValue':
'Fn::Sub': >-
${EnvironmentName}${SettingsServiceStackName}:${EnvironmentName}CreateWidgetARN
ServiceRoleArn:
'Fn::GetAtt': CreateWidgetRole.Arn
CreateWidgetResolver:
Type: 'AWS::AppSync::Resolver'
Properties:
ApiId:
'Fn::GetAtt': GraphQLApi.ApiId
FieldName: createWidget
TypeName: Mutation
DataSourceName:
'Fn::GetAtt': CreateWidgetDataSource.Name

最佳答案

问题出在 template.yaml 中的 SettingsServiceResources 行。嵌套模板中的所有资源都有逻辑 ID(例如 CreateWidgetRole),因此无需在 Transform block 前面放置另一个 ID。以下内容对我有用:

Resources:
'Fn::Transform':
Name: 'AWS::Include'
Parameters:
Location:
'Fn::Sub': >-
s3://${S3Bucket}/included_templates/settings_service_resources_template.yaml

您还可以检查docs中的语法。 .

关于amazon-web-services - CloudFormation模板中的错误到底在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65011959/

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