以 Json 类型作为 cloudformation 模板的参数

Taking Json type as parameter for cloudformation template

我正在尝试将环境变量作为模板的参数: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-sagemaker-model-containerdefinition.html

模板中的类型似乎是Json,我不知道如何填充它。

如果我如下硬编码环境变量,我似乎可以定义它:

Resources:
  SageMakerModel:
    Type: 'AWS::SageMaker::Model'
    Properties:
      ExecutionRoleArn: 
        Ref: ExecutionRoleArn
      EnableNetworkIsolation: false
      PrimaryContainer:
        Environment:
          REQUEST_KEEP_ALIVE_TIME_SEC: '90'
        Image: 
          Ref: ImageURI

但是,似乎没有办法将其传入?有没有人想出这个或任何推荐的方法来做到这一点?

尝试这样的事情:

Environment: !Sub '{"REQUEST_KEEP_ALIVE_TIME_SEC": "${KeepAliveTimeSec}", "Env2": "Val2"}'

我能够通过使用 AWS:Include 和 Fn:Transform 并将我的环境变量作为 json 存储在传递的 s3 文件中来实现它。

我的 cfn 模板如下所示:

Resources:
  SageMakerModel:
    Type: 'AWS::SageMaker::Model'
    Properties:
      ExecutionRoleArn: 
        Ref: ExecutionRoleArn
      EnableNetworkIsolation: false
      PrimaryContainer:
        Environment:
          Fn::Transform:
            Name: AWS::Include
            Parameters:
              Location: <your S3 file>
        Image: 
          Ref: ImageURI

我的 s3 文件如下所示:

{
  "REQUEST_KEEP_ALIVE_TIME_SEC": "90"
}