How to change database config in AWS Elastic Beanstalk - amazon-web-services

In my AWS Elastic Beanstalk environment, I need to change the database config to use a different RDS instance.
Does anyone know how to do this at the AWS (SDK) Command line ?

I don`t believe there is a way to change to a different RDS instance using beanstalk command line client.
The way I suggest you manage your database configuration using Elastic Beanstalk is like that:
1) Do not create a database using the Elastic Beanstalk wizard. It is much better to create a separate RDS instance and then connect your Elastic Beanstalk server to it.
2) In your project, you should have a .env file listing all the connection parameters. IMPORTANT: This file should be listed in .gitignore. So while you are coding, you can switch between your dev, stage, and production environment easily.
3) In your AWS console, you should go to Beanstalk instance > Configuration > Software. Then list under Environment properties all the connection parameters using RDS pre-defined parameters.
This way you will have your servers configured and be able to switch between RDS instances in your IDE while coding.

Related

Change Elastic Beanstalk environment from Launch Configuration to Launch Template

The Elastic Beanstalk docs say:
Web server environments have ... one of the following two resources.
AWSEBAutoScalingLaunchConfiguration (AWS::AutoScaling::LaunchConfiguration) – The launch configuration attached to your environment's Auto Scaling group.
AWSEBEC2LaunchTemplate (AWS::EC2::LaunchTemplate) – The Amazon EC2 launch template used by your environment's Auto Scaling group.
AWS is in the process of deprecating Launch Configurations, as Launch Templates are strictly more featured. In particular, AWS has sent a notice to customers saying:
After December 31, 2022 no new Amazon Elastic Compute Cloud (Amazon EC2) instance types will be added to launch configurations.
How do I convert an Elastic Beanstalk environment that is currently using a Launch Configuration to use a Launch Template instead?
I have contacted AWS support about this issue. As of December 31 2022 AWS will deprecate launch configurations. So we have to use launch templates instead of launch configurations. And this is their response.
Firstly, the current guidance is that no action will be needed on your
end regarding the launch configuration deprecation. Beanstalk will use
launch configurations when needed, and will automatically use launch
templates for new instances and newer features as needed. However, I
will be sure to update you if this guidance changes.
However, if you wish to change your Elastic Beanstalk environments to
make use of launch templates instead of a launch configuration, I
suggest to enable the 'Disable IMDSv1' option in your EB environments
configuration [2]. IMDS is instance metadata service and is used by
code to access instance metadata. Disabling IMDSv1 requires using
Amazon EC2 launch templates. When you configure this feature during
environment creation or updates, Elastic Beanstalk attempts to
configure your environment to use Amazon EC2 launch templates (if the
environment isn't using them already).If you have custom scripts which
communicates with the IMDSv1 endpoint, then you will need to ensure
those are migrated to the newer IMDSv2 [3].
Additionally, please note that this may introduce some downtime while
the configuration changes are being applied to the environment. I
recommend creating a new environment and performing a Blue/Green
deployment [4] to minimize this potential downtime. Please test this
is in your non production and proceed to production based on the
results in non-production.
Please refer the provided documentation and let me know if you need
any help.
References:
[1] Managing environments - https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/using-features.managing.html
[2] Configuring IMDS using the Elastic Beanstalk console - https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/environments-cfg-ec2-imds.html#environments-cfg-ec2-imds.console
[3] IMDSv2 - https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-instance-metadata-service.html
[4] Blue/Green deployments with Elastic Beanstalk - https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/using-features.CNAMESwap.html
I was in this exact position. I connected with AWS support and the answer I received is that launch configurations being used in Elastic beanstalk apps will be migrated automatically behind the scenes. So if your only launch configurations are generated as part of an elastic beanstalk then you have nothing to do, and the notice only applies to configurations created outside of Elastic Beanstalk.

Installing dependencies through elastic beanstalk config files versus eb ssh

I am having trouble installing a specific dependency in my elastic beanstalk environment via a .config file in the .ebextensions directory.
Are there any issues caused by instead installing it directly onto the instance via "eb ssh"? If my application was auto-scaled or if I wanted to change the instance type, will the dependency be missing from these new instance(s)?
There will be issues when the application get's auto-scaled. An EC2 instance provisioned by Elastic Beanstalk has the following MOTD:
This EC2 instance is managed by AWS Elastic Beanstalk. Changes made via SSH
WILL BE LOST if the instance is replaced by auto-scaling. For more information
on customizing your Elastic Beanstalk environment, see our documentation here:
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html
Use the custom container approach suggested if you're aiming to create a highly customized beanstalk environment.

Multiple elastic beanstalk environment in one ec2 instance

I am using aws elastic beanstalk to host my django application. We need to setup dev, stage and Prod environment of the application. But whenever I am using eb create command, it is also launching a new ec2 instance for the new environment.
Is it possible to set up multiple elastic beanstalk Environment in single ec2 instance. Also if I want to host a WordPress website in one of these instance can I do so by ssh logging into your the system and putting website in public web directory ?
If you can host your application within a docker container then you can use Multicontainer Docker Environment and run multiple docker containers on the same environment.
Read about multi-container docker environments in ElasticBeanstalk here:
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_docker_ecs.html
No.
Elastic Beanstalk create EC2 instances per environment. U can have single instance or elastic instance setups.
Yes you can SSH onto an EB Instance.
No you can't expect your changes to remain. The message when you SSH onto the EB Instance says as much.
Its a managed service for you.
The concept of having your EB Elastic destroys your capability for baking the EC2 instance it makes.
Use your GIT repository to put the Wordpress site on the EB and use a Database to pre-define it.. however you'll have state and media issues to overcome...

Change RDS Configuration in Elastic Beanstalk App?

I want to change my RDS Instance that is connected to my Elastic Beanstalk Application, from a db.t1.micro to a db.m1.small. If I go to my Elastic Beanstalk Application and go to "Configuration", I can only see the current settings, but I'm unable to change them.
I then went into the Console -> RDS -> Instances, and updated my Instance from the RDS Menu, and set it as a db.m1.small. On RDS it now says that it's an db.m1.small, however on the Elastic Beanstalk Configuration Page, it still says that the application is running a db.t1.micro instance.
So a few questions:
Did I upgrade my instance in the "correct" way? Or is there another way I'm suppose to configure my RDS Instance that is set up with my Elastic Beanstalk App?
Any ideas why the different pages are saying different configurations?
If RDS console says that the RDS instance type is m1.small then it has been changed to m1.small. The two pages are showing different values because beanstalk provisioned a t1.micro instance instance for you and hence thinks you have a t1.micro db instance. If you rebuild your environment then the new environment should have the same configuration and hence a t1.micro instance.
Changing it via the RDS console does not change the configuration on Beanstalk, hence you see different values.
However if the RDS instance was created via Beanstalk then the correct way to update your db instance type would be using Elastic Beanstalk option settings.
You can make the change using AWS CLI if not using the console.
http://docs.aws.amazon.com/cli/latest/reference/
Just run the following command:
aws elasticbeanstalk --update-environment --environment-name <your-env-name> --option-settings Namespace=aws:rds:dbinstance,OptionName=DBInstanceClass,Value=db.m1.small
Try the above command.
More information on update-environment via aws cli:
http://docs.aws.amazon.com/cli/latest/reference/elasticbeanstalk/update-environment.html
Read more about option settings and ebextensions here.

How do you remove an RDS data layer from an Elastic Beanstalk environment

How do you remove an RDS database from an Elastic Beanstalk environment?
There doesn't appear to be an option to do this. I understand I can create an EB environment and have it create an RDS server with it, which we did. Now we just want to get raid of the RDS server by itself but leave the app servers running. I don't see how we're suppose to do this unless I just delete it from the RDS GUI, but I'd think the proper way to do it is remove it from the EB environment.
According to this answer on Amazon aws forums:
There is currently no way to remove RDS from an Elastic Beanstalk
configuration. You would need to create a new Elastic Beanstalk
application configuration that excludes the RDS configuration, launch
your app in this new environment, and then change DNS to point to the
new environment.
https://forums.aws.amazon.com/message.jspa?messageID=469364
It's 2019 and still not possible to remove an RDS database from an Elastic Beanstalk environment. I wish I had known this earlier.
Anyway ... here are the general steps necessary to create a new environment without a managed RDS DB (based on the same thread from the AWS forum):
Create a snapshot of your RDS DB and create a new RDS DB from it. This does not retain the security group, parameter group, or options of your DB. So it might be preferable to create a new empty RDS DB where you can configure everything and then restore the contents from a DB dump like mysqldump.
Save a configuration of your Elastic Beanstalk env and download it from your S3 EBS bucket under resources/templates/<your-app-name>/.
Modify the config to remove all references to RDS, and upload the modified file to your S3 bucket.
Create a new environment from the saved configuration. You should now have an env without a managed RDS DB. Some settings might not be carried over in this process. For example, I had to reconfigure the load balancer for my new env.
Once everything is working in the new env you can use "Swap Environment URLs" or point your DNS record to the new load balancer.
Now you can decouple the database from your environment.
Then it will follow the data retention policy you have set for it.
https://aws.amazon.com/premiumsupport/knowledge-center/decouple-rds-from-beanstalk/