Hi.
I am trying to put apache logs to cloud watch.
However i can’t.
There are no error information,then I can’t resolve by myself.
My environment is the following information.
Hi Shiratsu,
I haven’t used plugins for log redirection so my solution will be slightly different. One thing you can do is modify your app (Apache in this case) to output its logs to standard out. There’s a couple of ways you can do this but I think the symlink method should work fine (https://serverfault.com/questions/711168/writing-apache2-logs-to-stdout-stderr). Once that is done, you then create an IAM role that grants the EC2 instance that is running your container(s) the ability to create logs in Cloudwatch. At the time that I tested this all out, the ability to create Cloudwatch Loggroups on the fly wasn’t an option so you will have to go in and create the Loggroup for the containers to stream to. Once you have created and assigned the IAM role to the EC2 instance and also have the Log group created, you can then launch your container with the --log-driver=awslogs option and your apache logs should start streaming to Cloudwatch.
Thank you for replying.
I could understand almost thing.
However i am stil anxious,because i could not understand completely.
So i would like to confirm my understanding.
I have to do something.
At first
to set symlink for accesslog and errorlog
I think i don need to add the auth for create log.
Is that correct?
Then,
I have to create group by aws console.
Then,
to assign IAM role to the EC2 instance.
As i said before,i already could put log by command line.
I think i don need to add the auth for create log.
Is that correct?
Edit - just noticed that you are exporting your AWS access and secret key as env variables. I completely missed that on my first read through. Yeah that should work in terms of permissions but I would go ahead and create the role and assign it to the EC2 instance since I know that method works.
so you are able to create logs in Cloudwatch via the command line because the api key you have stored in your credentials file (on your local machine) is associated with an account that has those permissions. By creating an IAM role and assigning it to your EC2 instance, you are giving the EC2 instance the permissions to write logs as well. So you definitely want to perform the role creation steps (as a side note, you may be able to copy your api key on to the EC2 instance and configure it to use that to communicate with cloudwatch but that is a bit more complicated and honestly a bit less secure than using the IAM role route)
Once you have the role configured and assigned to the EC2 instance, the next step is to create the LogGroup in Cloudwatch that you are going to have your container(s) stream to and then finally you launch your container(s) with the with the appropriate cloudwatch options (–log-driver and --log-opt)
so for example, if I create a Cloudwatch Loggroup called mytest-web-logs, I would configure my container to send to it via the command below –
it just dawned on me that you posted your question in the Docker for AWS sub-forum. Are you trying to do this in a Docker Swarm (via the Docker for AWS template)? if so, then streaming to cloudwatch should already be taken care of for you and all you need to do is configure apache to log to stdout. Otherwise the steps that I noted above will work for getting logs into cloudwatch for containers not running in a Docker for AWS environment.
no need to apologize. Docker is still a fairly young product so it is going to take some time to hammer out all the proper steps for things. I will definitely type up the ‘how to’ doc as it could help other people down the road as well. I have a sick baby at home so I more than likely won’t get it written until this weekend. In the meantime let’s continue to troubleshoot this together. I noticed the AssumeRole error you get when trying to create the role. Any chance you can use the console to create the policy first (which has an option to validate your syntax prior to creation)? Basically, create the policy like the one I pasted here (yours should work as well), then assign that policy to a Role and finally assign that role to the EC2 instance.