如何在 AWS CloudFormation YAML 模板中格式化 JSON 数据类型的参数?

问题描述 投票:0回答:1

AWS CloudFormation 的 YAML 模板 文档

AWS::SageMaker::Model
ContainerDefinition
指定
Environment
的类型为 JSON。我不知道如何在 YAML 模板中提交 JSON,而在使用以下命令运行部署后不会导致“CREATE_FAILED 内部故障”。

aws cloudformation deploy --stack-name test1 --template-file test-template-export.yml

测试模板导出.yml

Description: Example yaml

Resources:
  Model:
    Type: AWS::SageMaker::Model
    Properties:
      Containers:
      - ModelPackageName: arn:aws:sagemaker:us-east-1:123456789123:model-package/name/25
      - Environment: '{"SAGEMAKER_CONTAINER_LOG_LEVEL": "20"}'
      ExecutionRoleArn: arn:aws:iam::123456789123:role/service-role/AmazonSageMakerServiceCatalogProductsUseRole

我也尝试过以下格式,但仍然没有成功。

Containers:
- ModelPackageName: arn:aws:sagemaker:us-east-1:123456789123:model-package/name/25
  Environment: '{"SAGEMAKER_CONTAINER_LOG_LEVEL": "20"}'

--

Containers:
- ModelPackageName: arn:aws:sagemaker:us-east-1:123456789123:model-package/name/25
- Environment: | 
         {
            "SAGEMAKER_CONTAINER_LOG_LEVEL": "20"
          }

--

Containers:
- ModelPackageName: arn:aws:sagemaker:us-east-1:123456789123:model-package/name/25
- Environment:
  - SAGEMAKER_CONTAINER_LOG_LEVEL: "20"

在没有环境的情况下运行部署良好。

我已经尝试了这个答案中的所有内容。 如何格式化这个

Environment
参数?

我的 aws cli 版本是“aws-cli/2.4.10 Python/3.8.8”

json amazon-web-services yaml aws-cloudformation amazon-sagemaker
1个回答
4
投票

嗨,当您看到 JSON 格式时,请多考虑一下 dict。 所以这样写:

Containers:
- ModelPackageName: arn:aws:sagemaker:us-east-1:123456789123:model-package/name/25
  Environment:
     SAGEMAKER_CONTAINER_LOG_LEVEL: 20

对于 IAM 策略,

PolicyDocument
是 JSON 类型,这就是 AWS 在其示例中的做法:

Type: 'AWS::IAM::Policy'
Properties:
  PolicyName: CFNUsers
  PolicyDocument:
    Version: "2012-10-17"
    Statement:
      - Effect: Allow
        Action:
          - 'cloudformation:Describe*'
          - 'cloudformation:List*'
          - 'cloudformation:Get*'
        Resource: '*'
  Groups:
    - !Ref CFNUserGroup
© www.soinside.com 2019 - 2024. All rights reserved.