4

Maybe this is pretty silly, but if I create a ECS task definition (see for example Step 6 of https://aws.amazon.com/blogs/compute/better-together-amazon-ecs-and-aws-lambda/), how can I read the environment variables inside my Python script?

Is it as simple as os.environ["AWS_REGION"]? or should I need to use the boto3 route, eg, http://boto3.readthedocs.org/en/latest/reference/services/ecs.html#ECS.Client.describe_task_definition?

Thanks for your help

4

1 回答 1

3

如果您提供 ECS 任务定义 JSON 的环境部分,则可以从容器中读取这些内容,因此您应该能够使用这些os.environ['ENVVAR']行。

            'environment': [
                {
                  'foo': 'bar'
                }
            ]

可以通过 bash 访问,$foo因此您的代码没有理由无法访问它。

于 2016-03-17T01:38:23.520 回答