gpt4 book ai didi

amazon-web-services - 如何在此 cloudformation 模板的 aws cli 命令中插入参数?

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

我尝试使用示例 cloudformation 模板创建资源,但它引发以下错误。

我使用的命令

aws cloudformation create-stack \
> --stack-name explaining-credit-decisions \
> --template-body file://template.yaml

我遇到的错误

An error occurred (ValidationError) when calling the CreateStack operation: 
Parameters: [SolutionPrefix] must have values

这是我使用的模板。


AWSTemplateFormatVersion: 2010-09-09
Description: >
(SA0003) -
sm-soln-explaining-credit-decisions:
Used as root template for 'explaining credit decisions' stack.
Version 1
Parameters:
SolutionPrefix:
Type: String
Description: |
Used to name resources created as part of this stack (and inside nested stacks too).
Can be the same as the stack name used by AWS CloudFormation, but this field has extra
constraints because it's used to name resources with restrictions (e.g. Amazon S3 bucket
names cannot contain capital letters).
AllowedPattern: '^sm-soln-explaining-[a-z0-9\-]{1,20}$'
ConstraintDescription: Only allowed to use lowercase letters, hyphens and/or numbers. Should start with 'sm-soln-explaining-' for permission management. Should be 39 characters or less.
CreateSageMakerNotebookInstance:
Description: Create a SageMaker Notebook Instance as part of the stack?
Type: String
Default: 'true'
AllowedValues:
- 'true'
- 'false'
SageMakerNotebookInstanceType:
Description: |
Amazon SageMaker Notebook instance type
Type: String
Default: ml.t3.medium
StackVersion:
Description: |
CloudFormation Stack version.
Use 'release' version unless you are customizing the
CloudFormation templates and solution artifacts.
Type: String
Default: release
AllowedValues:
- release
- development
Mappings:
SolutionsS3BucketNamePrefix:
development:
Prefix: sagemaker-solutions-build
release:
Prefix: sagemaker-solutions
Conditions:
CreateSageMakerNotebookInstance: !Equals [ !Ref CreateSageMakerNotebookInstance, 'true' ]
Resources:
S3Bucket:
Type: "AWS::S3::Bucket"
Properties:
BucketName: !Sub ${SolutionPrefix}-${AWS::Region}-${AWS::AccountId}
PublicAccessBlockConfiguration:
BlockPublicAcls: true
BlockPublicPolicy: true
IgnorePublicAcls: true
RestrictPublicBuckets: true
BucketEncryption:
ServerSideEncryptionConfiguration:
-
ServerSideEncryptionByDefault:
SSEAlgorithm: AES256
Metadata:
cfn_nag:
rules_to_suppress:
- id: W35
reason: Avoids user having to manually create an Amazon S3 bucket for logs.
- id: W51
reason: Current default access policy is sufficient.
GlueStack:
Type: "AWS::CloudFormation::Stack"
Properties:
TemplateURL: !Sub
- "https://${SolutionsS3BucketNamePrefix}-${AWS::Region}.s3.amazonaws.com/Explaining-credit-decisions/cloudformation/glue/glue.yaml"
- SolutionsS3BucketNamePrefix:
Fn::FindInMap: [SolutionsS3BucketNamePrefix, Ref: StackVersion, Prefix]
Parameters:
SolutionPrefix: !Ref SolutionPrefix
S3BucketName: !Ref S3Bucket
SolutionsS3BucketName: !Sub
- ${SolutionsS3BucketNamePrefix}-${AWS::Region}
- SolutionsS3BucketNamePrefix:
Fn::FindInMap: [SolutionsS3BucketNamePrefix, Ref: StackVersion, Prefix]
SageMakerStack:
Type: "AWS::CloudFormation::Stack"
Properties:
TemplateURL: !Sub
- "https://${SolutionsS3BucketNamePrefix}-${AWS::Region}.s3.amazonaws.com/Explaining-credit-decisions/cloudformation/sagemaker/sagemaker.yaml"
- SolutionsS3BucketNamePrefix:
Fn::FindInMap: [SolutionsS3BucketNamePrefix, Ref: StackVersion, Prefix]
Parameters:
SolutionPrefix: !Ref SolutionPrefix
StackVersion: !Ref StackVersion
S3BucketName: !Ref S3Bucket
GlueDatabase: !GetAtt GlueStack.Outputs.GlueDatabase
GlueWorkflow: !GetAtt GlueStack.Outputs.GlueWorkflow
SolutionsS3BucketName: !Sub
- ${SolutionsS3BucketNamePrefix}-${AWS::Region}
- SolutionsS3BucketNamePrefix:
Fn::FindInMap: [SolutionsS3BucketNamePrefix, Ref: StackVersion, Prefix]
CreateSageMakerNotebookInstance: !Ref CreateSageMakerNotebookInstance
SageMakerNotebookInstanceType: !Ref SageMakerNotebookInstanceType
SolutionAssistantStack:
Type: "AWS::CloudFormation::Stack"
Properties:
TemplateURL: !Sub
- "https://${SolutionsS3BucketNamePrefix}-${AWS::Region}.s3.amazonaws.com/Explaining-credit-decisions/cloudformation/solution-assistant/solution-assistant.yaml"
- SolutionsS3BucketNamePrefix:
Fn::FindInMap: [SolutionsS3BucketNamePrefix, Ref: StackVersion, Prefix]
Parameters:
SolutionPrefix: !Ref SolutionPrefix
S3BucketName: !Ref S3Bucket
SolutionsS3BucketName: !Sub
- ${SolutionsS3BucketNamePrefix}-${AWS::Region}
- SolutionsS3BucketNamePrefix:
Fn::FindInMap: [SolutionsS3BucketNamePrefix, Ref: StackVersion, Prefix]
ECRRepository: !GetAtt SageMakerStack.Outputs.ECRRepository
Outputs:
AwsAccountId:
Value: !Ref AWS::AccountId
AwsRegion:
Value: !Ref AWS::Region
EcrRepository:
Value: !GetAtt SageMakerStack.Outputs.ECRRepository
ContainerBuildProject:
Value: !GetAtt SageMakerStack.Outputs.ContainerBuildProject
GlueDatabase:
Value: !GetAtt GlueStack.Outputs.GlueDatabase
GlueWorkflow:
Value: !GetAtt GlueStack.Outputs.GlueWorkflow
SolutionPrefix:
Value: !Ref SolutionPrefix
S3Bucket:
Value: !Ref S3Bucket
IamRole:
Value: !GetAtt SageMakerStack.Outputs.SageMakerIAMRole
SagemakerNotebookInstanceNotebooks:
Description: URL to notebooks on the Amazon SageMaker Notebook Instance.
Condition: CreateSageMakerNotebookInstance
Value: !GetAtt SageMakerStack.Outputs.SageMakerNotebookInstanceNotebooks
SagemakerMode:
Value: !If
- CreateSageMakerNotebookInstance
- "NotebookInstance"
- "Studio"

原因是什么?

最佳答案

它在文档中:https://docs.aws.amazon.com/cli/latest/reference/cloudformation/create-stack.html

您需要通过 --parameters 开关向 Cloudformation 参数提供值。

--parameters (list)

A list of Parameter structures that specify input parameters for the stack. For more information, see the Parameter data type.
(structure)
The Parameter data type.
ParameterKey -> (string)
The key associated with the parameter. If you don't specify a key and value for a particular parameter, CloudFormation uses the default value that's specified in your template.
ParameterValue -> (string)
The input value associated with the parameter.

文档中的示例:

aws cloudformation create-stack --stack-name myteststack \
--template-body file://sampletemplate.json --parameters \
ParameterKey=KeyPairName,ParameterValue=TestKey ParameterKey=SubnetIDs,ParameterValue=SubnetID1\\,SubnetID2

关于amazon-web-services - 如何在此 cloudformation 模板的 aws cli 命令中插入参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76243250/

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