Setting static file in elastic beanstalk - django

Trying to have django look for static files in the right directory, when hosting with elastic beanstalk.
Config file:
option_settings:
"aws:elasticbeanstalk:container:python:staticfiles":
"/static/": "static"
Getting error message:
ERROR Invalid option specification (Namespace: 'aws:elasticbeanstalk:container:python:staticfiles', OptionName: '/static/'): Unknown configuration setting.
Tried following code from the documentation as a test.
option_settings:
aws:elasticbeanstalk:application:environment:
DJANGO_SETTINGS_MODULE: production.settings
aws:elasticbeanstalk:container:python:staticfiles:
/html: statichtml
/images: staticimages
Getting the same 'unknown configuration settings' error.

It seems you are using Amazon Linux 2? If yes, then it does not support the aws:elasticbeanstalk:container:python:staticfiles.
From docs:
Configuring static files using the
aws:elasticbeanstalk:container:python:staticfiles namespace is only
supported on Amazon Linux AMI Python platform versions

The answer for Amazon Linux 2 is to change:
aws:elasticbeanstalk:container:python:staticfiles:
/html: statichtml
/images: staticimages
to
aws:elasticbeanstalk:environment:proxy:staticfiles:
/html: statichtml
/images: staticimages

Related

Can't set RDS while creating Elastic Beanstalk

I'm trying to create a Elastic Beanstalk environment with node.js platform. When I try to add RDS in EB, console is throwing error and I don't know the reason why. If you have any idea, plz leave a comment, thanks.
Configuration validation exception: Invalid option value: '5.6' (Namespace: 'aws:rds:dbinstance', OptionName: 'DBEngineVersion'): Engine Version 5.6 not supported for mysql db
error
You can fix this by running:
$ eb config
The command is going to open a notepad with your configuration settings. Scroll down to the bottom until you see aws:rds:dbinstance add a new setting specifying a newer MySQL version (eg. 8.0) like so:
aws:rds:dbinstance:
HasCoupledDatabase: 'false'
DBEngineVersion: '8.0'
Save and close the file. Your EB environment is going to update and you're then going to be able to change RDS settings via EB Console.
For beginners... you should use "eb cli" to use $eb config
and it worked for me, it is great answer. Thanks #duplxey
Something must gone wrong with elastic beanstalk with my

Deploying simple docker app with docker-compose on Elastic Beanstalk

I have a simple docker app that is able to run for me locally via docker-compose up, and when I send the .yml file to my friend, they are also able to get it up and running on their local machine. However, when I try to deploy it on Elastic Beanstalk, I get errors (specifically, something related to error:open /var/pids/eb-docker-compose-log.pid: no such file or directory, as I'll show below). I've tried to upload multiple times to Elastic Beanstalk, with the same errors. This is a custom app, but they are the same errors I got when I was trying to follow the instructions on https://docker-curriculum.com/#docker-on-aws. Here is the docker-compose.yml for my current app:
version: "3"
services:
server:
image: mfatigati/shop-server
container_name: shop-server
ports:
- "4000:4000"
client:
image: mfatigati/shop-client
depends_on:
- server
ports:
- "3000:3000"
mfatigati/shop-server and mfatigati/shop-client are both Node.JS apps, i.e., FROM node:16 in their Dockerfile.
To deploy this on AWS, I go to my EB console, and then:
Click "Create Application" to take me to the create app screen
Choose "Docker" as the platform
Choose "Upload local code", and upload the above-mentioned .yml file.
Click "Create Application"
Based on the notes here, I think this should be all I need to do (maybe I'm wrong about that?), but I get errors every time that point me to the eb.engine.log file. I've pasted what seems to be the relevant section below, as it is the only section that mentions errors, and it also reflects what appears in the AWS GUI console. The main problem seems reflected by the bit about error:open /var/pids/eb-docker-compose-log.pid: no such file or directory:
2022/02/14 14:17:23.619888 [ERROR] update processes [cfn-hup eb-docker-events healthd eb-docker-compose-events eb-docker-compose-log docker] pid symlinks failed with error Read pid source file /var/pids/eb-docker-compose-log.pid failed with error:open /var/pids/eb-docker-compose-log.pid: no such file or directory
2022/02/14 14:17:23.619901 [ERROR] An error occurred during execution of command [app-deploy] - [Track pids in healthd]. Stop running the command. Error: update processes [cfn-hup eb-docker-events healthd eb-docker-compose-events eb-docker-compose-log docker] pid symlinks failed with error Read pid source file /var/pids/eb-docker-compose-log.pid failed with error:open /var/pids/eb-docker-compose-log.pid: no such file or directory
2022/02/14 14:17:23.619905 [INFO] Executing cleanup logic
2022/02/14 14:17:23.620005 [INFO] CommandService Response: {"status":"FAILURE","api_version":"1.0","results":[{"status":"FAILURE","msg":"Engine execution has encountered an error.","returncode":1,"events":[{"msg":"Instance deployment failed. For details, see 'eb-engine.log'.","timestamp":1644848243,"severity":"ERROR"}]}]}
Any insight would be greatly appreciated! I'm pasting some screenshots below, in case that helps.
GUI corresponding to step 2; GUI corresponding to step 3; GUI errors
I had the same error:open /var/pids/eb-docker-compose-log.pid: no such file or directory error happening for my Docker Compose app when trying to deploy it to my Elastic Beanstalk environment; I'm not sure if my solution will be the same solution you need, but I hope it points you in the right direction (and helps future devs facing a similar problem).
What caused the error for me:
This ...eb-docker-compose-log.pid: no such file... error was a false error that was triggered by a separate issue; my separate error was actually a problem with my application code not finding the environment variables set in my Elastic Beanstalk environment. See below for how I found the problem, and what I did to fix it.
How I found my real problem:
I downloaded the Full Logs:
go to your EB environment
click Logs on the left nav
click the Request Logs dropdown button (at the top right)
click Full Logs
click the Download link once the full logs are ready
Inside of the logs, I found the real problem in the eb-docker/containers/eb-current-app/eb-stdouterr.log file, the issue being that my application code wasn't able to find the environment variables that were setup in my Elastic Beanstalk Software configuration.
In case you're curious what my error said:
panic: required key ONE_OF_MY_ENV_KEYS missing value
(I also had a couple other errors in this log that I fixed, but fixing the error shown above is what ended up solving the ...eb-docker-compose-log.pid: no such file... error).
How I fixed this error:
I turns out that if you use docker-compose.yml, while setting up your environment variables in your Elastic Beanstalk Software configuration, you have to make sure you use the .env file that Elastic Beanstalk creates for you; otherwise (from my own testing), EB only see's/uses the environment variable keys/values you specify in your own .env file or environment: list you can specify in docker-compose.yml.
NOTE: see the Elastic Beanstalk "Environment properties and Environment Variables" and "Referencing environment variables in containers" sections in the docs here, in particular this bit:
"Elastic Beanstalk generates a Docker Compose environment file called .env in the root directory of your application project. This file stores the environment variables you configured for Elastic Beanstalk.
Note
If you include a .env file in your application bundle, Elastic Beanstalk will not generate an .env file."
I solved my problem by updating my docker-compose.yml file to point to the supposed .env file that EB would create for me (by adding env_file: .env to my services that needed it), i.e.:
version: "3"
services:
my_service1:
# ...
env_file: .env
my_service2:
# ...
env_file: .env

AWS Elastic Beanstalk ERROR: InvalidParameterValueError

While using command - eb deploy
I am getting below error. YAML is fine syntax wise
ERROR: InvalidParameterValueError - Each option setting in configuration file .ebextensions/environ-
v1.config in application version app-4c59-191023_045651 must be a map. Update each option setting in the configuration file.
.config file in .ebextensions folder which is in root of project
option_settings:
aws:elasticbeanstalk:application:environment:
PORT:8081
NODE_ENV:development
aws:autoscaling:launchconfiguration:
SecurityGroups:launch-123
I ran into the same issue running the AWS Deploy a Django App to Elastic Beanstalk (the tutorial does not seem to be up to date).
This AWS page has some info on the latest option setting formatting
It helped me resolve my issue which I think in your case would be including spaces after "PORT: ", "NODE_ENV: ", etc.
Also using an IDE that will highlight different words/parts of the file helped me understand how things were getting recognized.
have you tried double quotes in .config file like
"aws:elasticbeanstalk:application:environment":
instead of
aws:elasticbeanstalk:application:environment:
and, respectively,
"aws:autoscaling:launchconfiguration":
instead of
aws:autoscaling:launchconfiguration:

How to set composer flag --no-dev for Amazon AWS deployment

I'm trying to deploy my Symfony 3 app on Amazon AWS Elastic beanstalk. I'm creating a folder ebextentions in root dir. In this dir I'm add a composer.config file which contains such code:
options_settings:
aws:elasticbeanstalk:container:php:phpini:
composer_options: --no-dev
but it doesn't work for me.
So, what config and where should I make for deploy project without developer requirements?
I just run into this same issue..
checking the eb-activity.log the --no-dev argument wasn't getting passed.
Here's what worked for me:
option_settings:
- namespace: aws:elasticbeanstalk:container:php:phpini
option_name: composer_options
value: --no-dev
The Amazon documentation seems misleading / incorrect..
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_PHP.container.html#php-namespaces
Assuming you did put the config file in .ebextensions instead of ebextensions, the real issue is that the options_settings key is a misspelling. It should actually be option_settings:
option_settings:
aws:elasticbeanstalk:container:php:phpini:
composer_options: --no-dev
Here's the relevant documentation for reference.
The problem is that your folder name is wrong. You are using ebextentions when the file should be named .ebextentions (there is a dot at the beginning).
See this answer for a full example.

How do specify an environment name for elastic bean stalk?

I am trying to deploy to elastic beanstalk using the cli.
The command I run is
eb create --modules ebtargets/goapi -v
I get the following error
WARNING: You have uncommitted changes.
INFO: Getting version label from git with git-describe
INFO: Uploading archive to s3 location: goapi/app-d4ec2-160630_135740.json
Uploading goapi/app-d4ec2-160630_135740.json to S3. This may take a while.
Upload Complete.
INFO: Creating AppVersion app-d4ec2-160630_135740
--- Waiting for application versions to be pre-processed ---
Finished processing application version app-d4ec2-160630_135740
--- Creating modules ---
ERROR: ServiceError - ApplicationVersion app-d4ec2-160630_135740 must specify an environment name in env.yaml
I have the key EnvironmentName in my env.yaml file. Any help on this?
I had a similar problem and I noticed you have to check your env.yaml into version control otherwise it won't be used:
git add env.yaml
git commit -m "add elastic beanstalk environment config"
Check that you have an .elasticbeanstalk folder into your ebtargets/goapi
If necessary, use eb init --modules ebtargets/goapi.
More information here