Certificate paths for Elastic Beanstalk instance - amazon-elastic-beanstalk

I'm trying to run CLI commands on new beanstalk instances when they start.
The CLI commands require env vars so I've set these in my bash script:
export EC2_BASE=/opt/aws
export EC2_HOME=$EC2_BASE/apitools/ec2
export EC2_PRIVATE_KEY=$(ls $EC2_BASE/certificates/*-pk.pem)
export EC2_CERT=$(ls $EC2_BASE/certificates/*-cert.pem)
export EC2_URL=https://ec2.amazonaws.com
export PATH=$PATH:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:$EC2_HOME/bin
export JAVA_HOME=/usr
In the logs I see the certificate paths are not working and causing errors.
ls: cannot access /opt/aws/certificates/*-pk.pem: No such file or directory
What is the correct path for the certificates?
I'm using the default linux ami.
The point of all this is to dynamically assign an elastic ip.

Elastic Beanstalk EC2 instances don't contain Private Key File and X.509 Certificate, you must upload them by yourself.

Related

Using aws cli without a homedirectory

I need to use aws cli on an OpenShift Cluster that is quite restricted - it looks like the homedirectory is set to /, while the user in the container does not have permissions to write to /.
The only directory that is writeable from that user is /tmp. Now I need to use aws cli from within a pod of this OpenShift cluster. I came across the environment variables AWS_CONFIG_FILE and AWS_SHARED_CREDENTIALS_FILE. So I would place each a credentials file and a config file to /tmp.
When running aws configure list-profiles with this setup, only the one profile from AWS_SHARD_CREDENTIALS_FILE is listed. Not the one from AWS_CONFIG_FILE.
So it looks to me like AWS_CONFIG_FILE is not respected by aws cli.
Do you have an idea why these files might not be respected by the aws executable? Is there a way to pass the location of these files directly to the cli as parameter or s.th.?
Instead of configuring files for the AWS CLI, I would assume you could set the following 2 environment variables: AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY and issue your CLI commands immediately.
bruno#pop-os ~> export AWS_ACCESS_KEY_ID="AKIAIOSFODNN7EXAMPLE"
bruno#pop-os ~> export AWS_SECRET_ACCESS_KEY="wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
bruno#pop-os ~> aws cloudformation list-stacks --region us-east-2
{
"StackSummaries": []
}
To answer on:
So it looks to me like AWS_CONFIG_FILE is not respected by aws cli.
The AWS CLI does respect this.
You can specify a non-default location for the config file by setting
the AWS_CONFIG_FILE environment variable to another local path.

How to convert elastic beanstalk classic load balancer to application load balancer on a running application?

I have several EB applications that I would like to convert from a classic to an application load balancer. In the documentation it seems that the default way is to create a new environment from scratch with the proper load balancer. Considering that I have many environment variables and several environments, I would prefer not to have to rebuild applications. Is there a way to switch out the load balancer on an already running application?
It is not possible to set a a load balancer type except at creation time. You can use elastic beanstalk cli and aws cli to clone the application with the same config and version. To get the deployed application version run:
aws elasticbeanstalk describe-environments --application-name ${APPLICATION_NAME} --environment-names ${SRC_ENV_NAME} | jq -r '.Environments | .[] | .VersionLabel'
The jq pipe filters out the rest of the json blob.
After that, you can save the config of the curent appication using:
eb config save $SRC_ENV_NAME --cfg "${SRC_ENV_NAME}_save"
Then create an application clone using:
eb create $NEW_ENV_NAME --elb-type application --cfg "${SRC_ENV_NAME}_save" --version $APP_VERSION
Where APP_VERSION is the string extracted in step one.
It is not simple, but it can be done.
If the Envivornment name is important to you, it gets a little trickier.
Here is it how it should go, step by step (using the web console):
Save the configuration of the Environment you want to change
From the Saved config, generate a new Env (select Customize settings)
2.1) Change the LB type to Application and fill out all the necessary info for this
Swap the URLs from the original env to the new one (check if everything is working with the new env, if not swap back)
[STEPS ONLY NECESSARY IF ENV NAME IS IMPORTANT]
Delete the original env (which now is not receiving traffic and has a Classic LB)
Wait until the original name disappears from the console (it make take a couple of hours)
Clone the production env, and give the new env the original env name
Swap URLs
Done!

AWS Elastic Beanstalk application folder on EC2 instance after deployed?

My context
I'm having errors in my deployment using AWS EB with my Flask application.
Now I'm inside the EC2 instance via eb ssh and need to explore the deployed source code of the application.
My problem
Where is the deployed application folder?
The source code is zipped and placed in the following directory:
/opt/elasticbeanstalk/deploy/appsource/source_bundle
There is no file extension but it is in the zip file format:
[ec2-user#ip ~]$ file /opt/elasticbeanstalk/deploy/appsource/source_bundle
/opt/elasticbeanstalk/deploy/appsource/source_bundle: Zip archive data, at least v1.0 to extract
Find for a specific/unique filename in source code folder, we will find the location of our application folder which, in AWS EB, to be
/opt/python/current
/opt/python/bundle/2/app
p.s.
Search for YOUR_FILE.py
find / -name YOUR_FILE.py -print

How to change the active configuration profile in gcloud?

I have created a new configuration profile using command:
gcloud init
and now I don't know how to switch to old configuration profile without override it.
Using gcloud config I can't switch to another configuration only set a property of the current configuration.
any idea?
You can see your configurations (created via gcloud init) via
gcloud config configurations list
You can switch to a different configuration via
gcloud config configurations activate MY_OLD_CONFIG
Once activated you can
gcloud config list
to see its settings.
You can also do this without activation by running
gcloud config list --configuration CONFIGURATION_NAME
I wrote a small Bash tool for anyone who needs to do this on a regular basis: https://github.com/uhinze/gconf
To list configs: gconf
To switch to a different config: gconf <CONFIG>
To then switch to the previous config (helpful when you're working with 2): gconf -

How to create Elastic beanstalk configuration template for a Environment

Whenever i create a new Environment in Elastic Beanstalk, i manually configure the Custom AMI ID, SNS notifications etc., but i want to do it automatically i.e, save the settings(custom AMI ID, SNS, key-pair etc.,) into a configuration template. Is it through Command line tools or from AWS management console that we can create this Configuration Template. Please suggest me.
You can easily do this through Amazon's web console. If you have a configuration you like just press save configuration. You can then use edit/load configuration to push that to new environments
If you are using the elastic beanstalk command line tools, when you setup an environment using the command git aws.config it creates a directory called .elasticbeanstalk with a file in it called config that looks like this:
[global]
AwsCredentialFile=/path/to/file/with/aws/account/credentials
ApplicationName=YourAppName
DevToolsEndpoint=git.elasticbeanstalk.your-region-name.amazonaws.com
EnvironmentName=yourEnvName
Region=your-region-name
Hope that helps!
Elastic Beanstalk's console is pretty lacking when it comes to configuring templates. You can't update or delete templates. There is a command line tool for full control.
You can also get the AWS Eclipse plugin. It's not as full featured like the CLI, but much better than web console.