gpt4 book ai didi

amazon-web-services - 来自 github 的模板路径无效,但直接在 cli Cloudformation 中执行时无效

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

我尝试从 github 执行 aws cloudformation 部署,但它表明模板格式错误。从 CLi 控制台或直接在 AWS Cloudformation 中执行相同的操作时,如果生成堆栈,可能会出现什么问题?

AWSTemplateFormatVersion: "2010-09-09"
Description: Template para la creacion de Lambdas en AWS CloudFormation.
Parameters:
Ambiente:
Type: String
Description: Ambiente (Ej desarrollo, preproduccion o produccion).
AllowedPattern: ^.*[^0-9]$
ConstraintDescription: Must end with non-numeric character.
LambdaName:
Type: String
Description: Nombre del lambda que se desea crear.
AllowedPattern: ^.*[^0-9]$
ConstraintDescription: Must end with non-numeric character.
Runtime:
Type: String
Description: Version de Nodejs (Ej nodejs14.x, nodejs16.x , nodejs18.x)
AllowedPattern: ^.*[^0-9]$
ConstraintDescription: Must end with non-numeric character.

Outputs:
LambdaRoleARN:
Description: Role for Lambda execution.
Value:
Fn::GetAtt:
- LambdaRole
- Arn
Export:
Name:
Fn::Sub: "${AWS::StackName}-ExRole"
LambdaFunctionName:
Value:
Ref: LambdaFunction
LambdaFunctionARN:
Description: Lambda function ARN.
Value:
Fn::GetAtt:
- LambdaFunction
- Arn
Export:
Name:
Fn::Sub: arn:aws:lambda:sa-east-1:xxxxxxxxx:function:${LambdaName}
Resources:
LambdaRole:
Type: AWS::IAM::Role
Properties:
RoleName:
Fn::Sub: lambda-role-${LambdaName}
AssumeRolePolicyDocument:
Statement:
- Action:
- sts:AssumeRole
Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Version: 2012-10-17
ManagedPolicyArns:
- arn:aws:iam::aws:policy/AWSLambdaExecute
Path: /
LambdaFunction:
Type: AWS::Lambda::Function
Properties:
FunctionName:
Fn::Sub: lambda-${LambdaName}
Description: LambdaFunction of nodejs14.x.
Handler: index.handler
Runtime:
Fn::Sub: ${Runtime}
Code:
ZipFile: |
exports.handler = async (event) => {
// TODO implement
const response = {
statusCode: 200,
body: JSON.stringify('Hello from Lambda!'),
};
return response;
};
MemorySize: 512
Timeout: 60
Role:
Fn::GetAtt:
- LambdaRole
- Arn

aws cloudformation 部署 --template-file plantilla_test.yaml --stack-name plantillalambdagithub --capability CAPABILITY_IAM

最佳答案

在您的模板中,您定义了一些参数,但没有给出默认值。因此,您可以使用尝试执行的命令为它们提供值,也可以在 JSON 文件中定义它们。

使用命令执行

aws cloudformation deploy \
--template-file plantilla_test.yaml \
--stack-name plantillalambdagithub \
--parameter-overrides Runtime=nodejs18.x LambdaName=rainmaker Ambiente=produccion \
--capabilities CAPABILITY_IAM

您可以使用aws cloudformation deploy help来查找部署命令的每个参数的详细信息。

使用命令和 JSON 文件执行

创建参数的 JSON 文件

cat <<EOL > parameters.json
{
"Parameters":
{
"Runtime": "nodejs18.x",
"LambdaName": "rainmaker",
"Ambiente": "produccion"
}
}
EOL

执行部署命令

aws cloudformation deploy \
--template-file plantilla_test.yaml \
--stack-name plantillalambdagithub \
--parameter-overrides file://parameters.json \
--capabilities CAPABILITY_IAM

2个文件,即JSON文件和CFN模板都在同一目录下。

关于amazon-web-services - 来自 github 的模板路径无效,但直接在 cli Cloudformation 中执行时无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76923316/

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