我试图将环境变量作为模板的参数: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"
}