Passing .config file to AWS Elastic Beanstalk - amazon-web-services

I'm using the Elastic Beanstalk Command Line tool and the function eb config put config. According to the AWS Elastic Beanstalk documentation it is required that you name your file according to *.cfg.yml and place it inside the .elasticbeanstalk/saved_configs file (http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb3-config.html#eb3-configexample). I have done this, and it forces you to write Yaml. I don't know much about Yaml, but I have tried many different ways of writing my config file and I can't get EB to accept it. Below is basically what I think is the closest I've come (note actual names and url substituted below):
aws:
elasticbeanstalk:
create-configuration-template:
application_name: ProjectName
template_name: TemplateName
environment_id: EnvironmentName
- option_settings:
option_name: mongodb
value: "mongoAddress.com"
The error message for the above is:
ERROR: Error parsing configuration file as yaml or json. Yaml error: 'Invalid Yaml: while parsing a block mapping
in "<reader>", line 4, column 5:
application_name: ProjectName
^
expected <block end>, but found BlockEntry
in "<reader>", line 7, column 5:
- option_settings:
^
', Json error: 'Invalid JSON: Unexpected character (a) at position 0.'
and if I take away the "- " before option_settings then I get this error:
ERROR: Invalid Environment Configuration specification. Must specify configuration template version.
Any ideas? I've checked all over the internet and I can't find anything on this
EDIT: Here's some more on the template from the AWS docs: http://docs.aws.amazon.com/cli/latest/reference/elasticbeanstalk/create-configuration-template.html

Abhishek Singh from AWS got back to me on Twitter and shared this blog post from the AWS website.
https://blogs.aws.amazon.com/application-management/post/Tx1YHAJ5EELY54J/Using-the-Elastic-Beanstalk-EB-CLI-to-create-manage-and-share-environment-config
In summary, he recommends using "eb config save" then modifying the file so that you don't need to worry about format as much. The details of how to do this are in the post above.

Related

Can I patch a string value in a kubernetes configmap?

Trying to patch a string value in the data section of a kubernetes config map but running into an error.
kubectl patch configmap cm-example -n example-ns -p '{"data":{"application.yml":{"keycloak":{"auth-server-url":"https://server-url.domain.com/auth/"}}}}'
Getting the below error
The request is invalid: patch: Invalid value: "map[data:map[application.yml:map[keycloak:map[auth-server-url:https://server-url.domain.com/auth/]]]]": unrecognized type: string
I had the same issue when I tried to run a patch on my configmap map that holds a file that was supposed to be a yaml file.
The thing is, deployment, pod, jobs - they are yaml or json. BUT a file inside the config map is just a string. The patch will not know what to do and you will need to send the entire string, which is not very useful. Another thing to do is try a sed. But it does not give the same experience as running a patch on pod, deployment and so on - files that are really yaml or json.

AWS: ERROR: Pre-processing of application version xxx has failed and Some application versions failed to process. Unable to continue deployment

Hi I am trying to deploy a node application from cloud 9 to ELB but I keep getting the below error.
Starting environment deployment via CodeCommit
--- Waiting for Application Versions to be pre-processed --- ERROR: Pre-processing of application version app-491a-200623_151654 has
failed. ERROR: Some application versions failed to process. Unable to
continue deployment.
I have attached an image of the IAM roles that I have. Any solutions?
Go to your console and open up your elastic beanstalk console. Go to both applications and environments and delete them. Then in your terminal hit
eb init #Follow instructions
eb create --single ##Follow instructions.
It would fix the error, which is due to some application states which are failed. If you want to check those do
aws elasticbeanstalk describe-application-versions
I was searching for this answer as a result of watching a YouTube tutorial for how to pass the AWS Certified Developer Associate exam. If anyone else gets this error as a result of that tutorial, delete the 002_node_command.config file created in the tutorial and commit that change, as that is causing the error to occur.
A failure within the pre-processing phase, may be caused by an invalid manifest, configuration or .ebextensions file.
If you deploy an (invalid) application version using eb deploy and you enable the preprocess option, The details of the error will not be revealed.
You can remove the --process flag and enable the verbose option to improve error output.
in my case I deploy using this command:
eb deploy -l "XXX" -p
And can return a failure when I mess around with .ebextensions:
ERROR: Pre-processing of application version xxx has failed.
ERROR: Some application versions failed to process. Unable to continue deployment.
With that result I can't figure up what is wrong,
but deploying without -p (or --process)and adding -v (verbose) flag:
eb deploy -l "$deployname" -v
It returns something more useful:
Uploading: [##################################################] 100% Done...
INFO: Creating AppVersion xxx
ERROR: InvalidParameterValueError - The configuration file .ebextensions/16-my_custom_config_file.config in application version xxx contains invalid YAML or JSON.
YAML exception: Invalid Yaml: while scanning a simple key
in 'reader', line 6, column 1:
(... details of the error ...)
, JSON exception: Invalid JSON: Unexpected character (#) at position 0.. Update the configuration file.
Now I can fix the problem.

How to use environment variables for Springboot application using a .env file?

I am trying to build a Springboot application which connects to a DB. I would like to use a .env file which has the sensitive content. At the first hand, I am testing by changing the port to 8081.
My .env file has the following content
PORT=8081
My application.properties has the following content
server.port=${PORT}
I have a run time error that PORT cannot be resolved, which is to be expected when I did not know how to feed the .env file to properties.
Could someone point me in the right direction?
PS: I am using the port as an example, if this succeeds I will also set the DB Credentials with the .env file.
UPDATE:
I would prefer using .env file because when the application is deployed using AWS CodePipeline, I can have the environment variables set in the CodeBuild stage where I would be building the jar and eventually a docker image in this stage. Something like this.
EnvironmentVariables:
- Name: PORT
Value: "{resolve:secretsmanager:DBCredentials:SecretString:port}"
The error is Caused by java.lang.IllegalArgumentException: Could not resolve placeholder 'PORT' in value "${PORT}"
I think you have the react approach ! But in spring for using multiple environments, it's better to have a properties file or yaml by environment.
Ps: File name must be named like application-{environment name}.properties and must be in the resources folder.
For dev:
File name : application-dev.properties
server.port=8089
For IT:
File name : application-it.properties
server.port=8090
In the application.properties file, where usually we put some shared properties between all the environments, we can add the propertie : spring.profiles.active = dev // you can put what you want depending on your needs. If you have more than one profile you can separate them by " , ".
For more details you can check spring profiles

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:

eb deploy ERROR: TypeError - cannot concatenate 'str' and 'NoneType' objects

Sorry I don't see this question anywhere. I've deployed an environment for my application "scones" on AWS. It's fairly simple Node.js express app. Honestly it's just to test the elastic beanstalk deployment. Anyhoo I'm using ebcli and I've already done an "eb create scones1" and it does create the environment and launches it. But when I make some changes (not committed to git) and type 'eb deploy' on the command line I receive ERROR: TypeError - cannot concatenate 'str' and 'NoneType' objects every time. Even if I enter the environment name. Doesn't matter. What is happening? None of the documentation seems to mention any error like this. Is there an issue with my Python version? I
I was having this same issue and determined it to be coming from the following line in ebcli/operations/deployops.py:
io.log_info('Deploying code to ' + env_name + " in region " + region_name)
I resolved it by explicitly specifying a region with -r REGION when executing the deploy. I imagine somewhere the default region should be configured so this does not happen.
Edit: I was able to permanently set the region with eb init --region us-east-1
Solve with a simple eb init, put my credentials, and just works.
Try git add . to stage your commits. Then, eb deploy --staged. You can check out the --staged flag here: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb3-deploy.html