gpt4 book ai didi

amazon-web-services - 将多个参数从外部文件传递到 cloudformation 模板并使用带有 ref 的值

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

尝试使用以下 cli 命令创建 cloudformation 堆栈时出现以下错误。

aws cloudformation create-stack --stack-name subodh-local-stack --template-url s3URL/template.json --parameters s3URL/params.json

Error: awscli.argprocess.ParamError: Error parsing parameter '--parameters': Unable to retrieve https://s3.amazonaws.com///params.json: received non 200 status code of 403 2017-08-18 01:32:31,309 - MainThread - awscli.clidriver - DEBUG - Exiting with rc 255

template.json:

{
"AWSTemplateFormatVersion": "2010-09-09",

"Resources": {
"Type": "AWS::Lambda::Function",
"Properties": {
"FunctionName": {
"Ref": "LambdaFunctionName"
},
"Handler": {
"Ref": "LambdaHandler"
},
"Role": {
"Ref": "LambdaExecutionRoleArn"
},
"Code": {
"S3Bucket": {
"Ref": "LambdaSourceBucket"
},
"S3Key": {
"Ref": "LambdaSourceKey"
}
},
"SubnetID": {
"Ref": "LambdaSubnetID"
},
"Runtime": "nodejs4.3",
"Timeout": "25",
"MemorySize": "128",
"VpcConfig": "vpc-2323454f",
"securityGroupID": "sg-0sdfs17g"
}
}
}

params.json:

[
{
"ParameterKey": "LambdaFunctionName",
"ParameterValue": "hello-world"
},
{
"ParameterKey": "LambdaHandler",
"ParameterValue": "index.handler"
},
{
"ParameterKey": "LambdaExecutionRoleArn",
"ParameterValue": "arn:aws:iam::312345678910:role/LambdaExecuteRole"
},
{
"ParameterKey": "LambdaSourceBucket",
"ParameterValue": "test-lambda-functions"
},
{
"ParameterKey": "LambdaSourceKey",
"ParameterValue": "helloworld.zip"
},
{
"ParameterKey": "LambdaSubnetID",
"ParameterValue": "subnet-1113121f,subnet-fer333ex"
}
]

将命令更新为:

aws cloudformation create-stack --stack-name test-local-stack --template-body file://c:/cli/aws/template.json --parameters file://c:/cli/aws/params.json

我收到错误

An error occurred (ValidationError) when calling the CreateStack operation: Template format error: [/Resources/Type] resource definition is malformed

我正在尝试使用 Ref 函数来引用在堆栈创建期间从参数文件传递的参数。

有人可以让我知道我做错了什么吗?

最佳答案

对于了解如何将外部参数文件与 CF 模板一起使用并使用 Ref 调用值的其他人:

主模板如下所示:

{
"AWSTemplateFormatVersion": "2010-09-09",
"Parameters": {
"LambdaFunctionName": {
"Description": "Lambda Function name",
"Type": "String"
}
...},
"Resources": {
"LambdaFunction": {
"Type": "AWS::Lambda::Function",
"Properties": {
"FunctionName": {
"Ref": "LambdaFunctionName"
}
},
...}
}

}

参数 json 文件应如下所示:

[
{
"ParameterKey":"LambdaFunctionName",
"ParameterValue":"hello-world"
},
....
]

感谢@olpa 引导我走向正确的方向。

关于amazon-web-services - 将多个参数从外部文件传递到 cloudformation 模板并使用带有 ref 的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45749424/

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