I have deployed an application using Amazon Elastic Beanstalk and I am using the EB CLI to access my logs.
Until recently when I did eb logs I was able to tail my logs. But now when I issue the same command, eb prints some binary data, for example:
-------------------------------------
/var/log/nginx/access.log-20150906.gz
-------------------------------------
^_<8B>^H^#<90><A5><EB>U^#^C<ED><9D><DF>s<E3><C8>q<C7><DF><F3>W<A8>
.......
As you can see the log file is gzipped. How can I make eb return the logs as text so I can read them?
Can you try eb logs --all as documented here. This will save the logs to a directory.
This problem is caused by elasticbeanstalk default configuration.
At least in 64bit Amazon Linux 2015.09 v2.0.4 running Ruby 2.2 (Puma) platform.
If you login to your instance with eb ssh and run cat /opt/elasticbeanstalk/tasks/taillogs.d/nginx.conf
You'll find out that by default eb logs tails every file in /var/log/nginx/ directory.
So we need to change /var/log/nginx/* to /var/log/nginx/*.log
It can be done by creating .ebextensions/0001_eb_logs.config file in root directory of your project.
File's content:
files:
"/opt/elasticbeanstalk/tasks/taillogs.d/nginx.conf" :
mode: "000644"
owner: root
group: root
content: |
/var/log/nginx/*.log
commands:
rm_old_conf:
command: "rm nginx.conf.bak"
cwd: "/opt/elasticbeanstalk/tasks/taillogs.d/"
ignoreErrors: true
Related
as of now elastic beanstalk allows to upload a single jar file for deployment.
i want to run custom script as per the below command for starting the application.
sudo java -Dlogging.file=/home/ec2-user/server.log -Xmx8192m -javaagent:/home/ec2-user/server/elastic-apm-agent-1.12.0.jar
-Delastic.apm.service_name=service-name
-Delastic.apm.application_packages=com.demo
-Delastic.apm.server_urls=xxx
-Delastic.apm.secret_token=XXX
-jar $server_name-0.0.1-SNAPSHOT.jar
--spring.profiles.active=prod
not sure if we can do it with some config file to specify the path of the java agent if we know the path of the java agent jar
In EB configuration > environment properties, you'd have to set JAVA_TOOL_OPTIONS=-javaagent:/home/ec2-user/server/elastic-apm-agent-1.12.0.jar and the rest of your -D and -Xmx properties in _JAVA_OPTIONS.
You will also need to download the agent using ebextensions config:
files:
"/home/ec2-user/server/elastic-apm-agent-1.12.0.jar":
mode: "000444"
owner: root
group: root
source: "https://<host>/elastic-apm-agent-1.12.0.jar"
I run a django app on eb. My goal is to create a cron script in /etc/cron.d at deployment time that runs django jobs. I tried to create it using a an eb configuration file, but so far I've been unable to create any file anywhere (manually checked by sshing into the host).
Platform: Python 3.7 running on 64bit Amazon Linux 2/3.3.9
The content of cron.config looks like this:
files:
"/etc/cron.d/cron_job":
mode: "000644"
owner: root
group: root
content: |
* * * * * root echo "Cron running at "`date` > /home/ec2-user/cron_job.log
What I've tried is following. In all cases, app deploys but no file created.
Placing cron.config in .ebextensions folder.
Placing cron.config in .platform/hook/postdeploy folder. Log says "The dir .platform/hooks/postdeploy/ does not exist in the application. Skipping this step...".
Specify file location as /tmp/cron_job.
Specify file location as /home/ec2-user/cron_job.
Would appreciate any help.
There is nothing wrong with your cron.config and it creates /etc/cron.d/cron_job. It works as expected as I run it on my own EB application. Whatever is happening is due to some other factors/code which is not shown in your question.
I recently was able to get my Laravel app deployed using codepipeline on Elastic Beanstalk but ran into a problem. I noticed that my routes where failing because of php.conf Nginx configuration. I had to add a few lines of code to EB's nginx php.conf file to get it to work.
My problem now was that after every deployment, the instance of the application I modified the php.conf file was destroyed and recreated fresh. I wanted a way to dynamically update the file after every successful deployment. I had a version of the file I wanted versioned with my application and so wanted to create a symlink to that file after deployment.
After loads of research, I stumbled on appDeploy Hooks on Elastic Beanstalk that runs post scripts after deployment so did this
files:
"/opt/elasticbeanstalk/hooks/appdeploy/post/91_post_deploy_script.sh":
mode: "000755"
owner: root
group: root
content: |
#!/usr/bin/env bash
sudo mkdir /var/testing1
sudo ln -sfn /var/www/html/php.conf.example /etc/nginx/conf.d/elasticbeanstalk/php.conf
sudo mkdir /var/testing
sudo nginx -s reload
And this for some reason does not work. The symlink is not created so my routes are still not working..
I even added some mkdir so am sure the commands in that script runs, none of those commands ran because none of those directories where created.
Please note that if I ssh into the ec2 instance and run the commands there it works. That bash script also exists in the post directory and if I manually run in on the server it works too.
Any pointers to how I could fix this would be helpful. Maybe I am doing something wrong too.
Now I have gotten my scripts to run by following this. However, the script is not running. I am getting an error
2020/06/28 08:22:13.653339 [INFO] Following platform hooks will be executed in order: [01_myconf.config]
2020/06/28 08:22:13.653344 [INFO] Running platform hook: .platform/hooks/postdeploy/01_myconf.config
2020/06/28 08:22:13.653516 [ERROR] An error occurred during execution of command [app-deploy] - [RunPostDeployHooks]. Stop running the command. Error: Command .platform/hooks/postdeploy/01_myconf.config failed with error fork/exec .platform/hooks/postdeploy/01_myconf.config: permission denied
I tried to follow this forum post here to make my file executable by adding to my container command a new command like so:
01_chmod1:
command: "chmod +x .platform/hooks/postdeploy/91_post_deploy_script.sh"
I am still running into the same issue. Permission denied
Sadly, the hooks you are describing (i.e. /opt/elasticbeanstalk/hooks/appdeploy) are for Amazon Linux 1.
Since you are using Amazon Linux 2, as clarified in the comments, the hooks you are trying to use do not apply. Thus they are not being executed.
In Amazon Linux 2, there are new hooks as described here and they are:
prebuild – Files here run after the Elastic Beanstalk platform engine downloads and extracts the application source bundle, and before it sets up and configures the application and web server.
predeploy – Files here run after the Elastic Beanstalk platform engine sets up and configures the application and web server, and before it deploys them to their final runtime location.
postdeploy – Files here run after the Elastic Beanstalk platform engine deploys the application and proxy server.
The use of these new hooks is different than in Amazon Linux 1. Thus you have to either move back to Amazon Linux 1 or migrate your application to Amazon Linux 2.
General migration steps from Amazon Linux 1 to Amazon Linux 2 in EB are described here
Create a folder called .platform in your project root folder and create a file with name 00_myconf.config inside the .platform folder.
.platform/
00_myconf.config
Open 00_myconf.config and add the scripts
files:
"/opt/elasticbeanstalk/hooks/appdeploy/post/91_post_deploy_script.sh":
mode: "000755"
owner: root
group: root
content: |
#!/usr/bin/env bash
sudo mkdir /var/testing1
sudo ln -sfn /var/www/html/php.conf.example /etc/nginx/conf.d/elasticbeanstalk/php.conf
sudo mkdir /var/testing
sudo nginx -s reload
Commit your changes or reupload the project. This .platform folder will be considered in each new instance creation and your application will deploy properly in all the new instances Amazon Elastic beanstalk creates.
If you access the documentation here and scroll to the section with the title "Application example with extensions" you can see an example of the folder structure of your .platform folder so it adds your custom configuration to NGINX conf on every deploy.
You can either replace the entire nginx.conf file with your file or add additional configuration files to the conf.d directory
Replace conf file with your file on app deploy:
.platform/nginx/nginx.conf
Add configuration files to nginx.conf:
.platform/nginx/conf.d/custom.conf
I've done this before a long time ago, but now it's not working... :)
I am trying to use EBExtensions in an ElasticBeanstalk application. I created a vanilla Elastic Beanstalk environment with no configuration beyond the defaults. I gave it an application version that had a directory structure like the following:
.ebextensions
40testextension.config
app.js
other files
The important part is that I have a folder called .ebextensions at the root of my deployable artifact, which is where I believe it should be located.
The 40testextension.config file inside that file has the following contents:
files:
"/home/ec2-user/myfile" :
mode: "000755"
owner: root
group: root
content: |
# This is my file
# with content
I uploaded that version when creating the environment, and the environment created successfully. But when I look for that file, it is not present. Furthermore, when do a recursive grep for that ebextension file name in the logs at /var/log, I only get one result:
./eb-activity.log: inflating: /tmp/deployment/application/.ebextensions/40testextension.config
Having looked at the logs, it seems that the file is present when the artifact gets pulled down to the host, but the ebextension never gives any indication of running.
What am I missing here? I've done this in the distant past and things have worked very nicely, but this time I can't seem to get the thing to be executed by the Beanstalk deploy lifecycle.
try to run it with -x Print commands and their arguments as they are executed to debug and try to change the mode to 000777.
files:
"/home/ec2-user/myfile" :
mode: "000777"
owner: root
group: root
content: |
#!/usr/bin/env bash
set -xe
I have a web app running on elastic beanstalk. For some reason I was able to install the composer files in order to run my laravel app. The problem is that no other config file works. I have put newrelic.config into the .ebextensions/ directory, but that file got ignored.
I recently tried to create a cron job using this, AWS Elastic Beanstalk, running a cronjob, but it is not working.
Example of a .config file:
container_commands:
01_some_cron_job:
command: "cat .ebextensions/some_cron_job.txt > /etc/cron.d/some_cron_job && chmod 644 /etc/cron.d/some_cron_job"
leader_only: true
When I ssh into the ec2 instance, there is no such directory as some_cron_job.
The source gets committed to beanstalk, but beanstalk is not running the commands.
How can I make beanstalk acknowledge the .config files. Fixing this cronjob will also fix installing new relic, because both configs are being ignored and I do not know why.
Try putting it in commands section. It is more of a server command than a container command.
commands:
01_some_cron_job:
command: "cat .ebextensions/some_cron_job.txt > /etc/cron.d/some_cron_job && chmod 644 /etc/cron.d/some_cron_job"
leader_only: true
I had similar issues as well using container_commands and files, however, I deferred to the files event and it worked like a charm. My specific setup is as below.
.ebextensions/cron.config
files:
"/etc/cron.d/mycronstuff":
mode: "000644"
owner: root
group: root
content: |
# Run daily job every 8 hours
0 */8 * * * root curl -i XXXXXXXXXX
# Run nightly job at 2AM (8AM UTC)
0 8 * * * root curl -i XXXXXXXXX
Update 2019:
You must use a cron.yaml file on your project directory.
inside the file you can mention:
version: 1
cron:
- name: "task1"
url: "/scheduled"
schedule: "* * * * *"