为 Cloudformation ECS + Fargate 部署添加环境变量

Pas*_*hal 3 aws-cloudformation docker-compose google-cloud-functions infrastructure-as-code

我们的镜像具有应该在 docker 运行期间定义的环境变量,知道如何将此变量添加到 cloudformation 文件中。我们目前有类似的东西:

Task:
Type: AWS::ECS::TaskDefinition
Properties:
  Family: testenv
  Cpu: 256
  Memory: 512
  NetworkMode: 
  RequiresCompatibilities:
    - FARGATE
  ExecutionRoleArn: !ImportValue ECSTaskExecutionRole
  ContainerDefinitions:
    - Name: bonalds
      Image: gcr.io/zonalds-21/id-me:latest // image comes from gcr
      Cpu: 256
      Memory: 512
      PortMappings:
        - ContainerPort: 4567
          Protocol: tcp
      LogConfiguration:
        LogDriver: 
        Options:
          awslogs-group: 'zonalds'
          awslogs-region: !Ref AWS::Region
          awslogs-stream-prefix: 'routme'
Run Code Online (Sandbox Code Playgroud)

我似乎在 AWS 文档中找不到任何信息,添加环境变量的最佳方法是什么?

Rob*_*dey 8

您的容器定义可以保存环境变量。

ContainerDefinitions:
    - Name: bonalds
      Image: gcr.io/zonalds-21/id-me:latest // image comes from gcr
      Cpu: 256
      Environment:
        - Name: Test
          Value: 'test'
      Memory: 512
      PortMappings:
        - ContainerPort: 4567
          Protocol: tcp
      LogConfiguration:
        LogDriver: 
        Options:
          awslogs-group: 'zonalds'
          awslogs-region: !Ref AWS::Region
          awslogs-stream-prefix: 'routme'
Run Code Online (Sandbox Code Playgroud)

文档中的更多信息