0

Here is my dockerfile.

FROM 796678920264.dkr.ecr.us-west-1.amazonaws.com/myproject/base:latest

COPY /* /


RUN python awslogs-agent-setup.py --non-interactive -c /aws-log.myservice.cfg --region us-west-2


CMD ["/start.sh"]

I use the dockerfile to build images that will be used in both dev and production environment. The behaviour is determined by an env variable. i.e. I will do something like this to start a docker container: docker run -e ENV=dev -ti myservice

One issue with this dockerfile is that: the logs in both dev and prod are sent to the same cloudwatch log in the region us-west-2.

Is there anything I can do to change the region for dev environment to a different value when a docker container is started? Preferably it should be controlled by the same environment variable.

Anthony Kong
  • 2,976
  • 10
  • 53
  • 91

1 Answers1

3

I add and call the following script in the main CMD script

if [ "$ENV"  != "prod" ]; then
    AWSLOG_CONF=/var/awslogs/etc/aws.conf
    sed -i -e 's/region = us-west-2/region = ap-southeast-1/g' $AWSLOG_CONF
    echo 'Set the awslog region to ap-southeast-1'
fi

The script must be called before the aws log service is started.

Anthony Kong
  • 2,976
  • 10
  • 53
  • 91
  • 1
    For anyone who installed awslogs via yum on amazon linux, region was set in /etc/awslogs/awscli.conf. Change it there as it was set to us-east-1 by default. – JavaRocky May 11 '18 at 00:58