Add a database to Elastic Beanstalk environments

lastic Beanstalk offers and Amazon Relational Database Service (Amazon RDS) is integrated to help you add to the database instance Elastic Beanstalk environment. You can use the Elastic Beanstalk environment during or after you create the MySQL, PostgreSQL, Oracle or SQL Server databases to your environment. When you add to your database instance environment, Elastic Beanstalk will be set by the database host name, port, user name, password, and database name of the environment property to provide the connection information to your application.

Part of your environment part of the database instance will be linked to the life cycle of the environment. After you add the database instance to the environment, you can not delete it from the environment. If the environment is terminated, it will terminate at the same time the database instance. You can configure Elastic Beanstalk so it saves a snapshot of the database at the time of termination of your environment, and restore the database from a snapshot when you add a database instance to the environment. You may incur costs to store the database snapshot.

For a production environment , you can start a database instance outside of your environment and application is configured to connect to the instance is outside the range of functions provided by Elastic Beanstalk. To use the database instance external environment, and require additional security groups connected string arrangement. However , it also enables you to connect to the database from multiple environments , using database database does not support the type of integration, the implementation of blue / green and disable your deployment environment, without affecting database instances.

After starting the database instance and configure the security groups, you can use environment property to the connection information (terminal node, password, etc.) to the application . This is when you run a database instance in your environment, Elastic Beanstalk using the same mechanism.

In the environmental attributes section, define the application reads the variables used to construct the connection string. For compatibility with the environment with integrated RDS database instance, use the following content.

  • RDS_HOSTNAME  - host name of the database instance.

    Amazon RDS Console tab -  terminal node (which is the host name)

  • RDS_PORT  - database instance accepts connections. The default value because the database engine to another.

    Amazon RDS Console tab -  port

  • RDS_DB_NAME  - the database name, ebdb .

    Amazon RDS Console tab -  Database name

  • RDS_USERNAME  - user name you configured for the database.

    Amazon RDS Console tab -  User Name

  • RDS_PASSWORD  - the password you configured for the database.

 

To improve security, you can connect the information stored in Amazon S3 , and Elastic Beanstalk is configured to retrieve the information during deployment. Using the configuration file (.ebextensions) , you can configure the instance environment to retrieve files from Amazon S3 safely when you deploy the application.

Amazon S3 is stored in the connection string

Using environment properties provide the connection information to the application is a good way to put a password outside of the code, but this is not a perfect solution. Environmental property in environmental management console found in the environment and can be right on the description of the configuration settings for any user to view. The platform, environment properties may also be shown in the example of the log in.

You can lock the connection by storing information stored in Amazon S3 buckets control information. The basic steps are as follows:

  • The file contains the connection string uploaded to Amazon S3 bucket.

  • EC2 instance configuration file to grant permissions to read the file.

  • Your application will be configured to download the file during deployment.

  • Reading the file in the application code.

First, create buckets to store file contains the connection string. In this example, we will use a single JSON file keys and values. This value is PostgreSQL Amazon RDS database instance of a JDBC connection string.

beanstalk-database.json

{ "connection": "jdbc:postgresql://mydb.b5uacpxznijm.us-west-2.rds.amazonaws.com:5432/ebdb?user=username&password=mypassword" }

 

------------------------------------------------------------------------------------------------------------

~/my-app/.ebextensions/database.config

 
Resources:
  AWSEBAutoScalingGroup:
    Metadata:
      AWS::CloudFormation::Authentication:
        S3Auth:
          type: "s3"
          buckets: ["my-secret-bucket-123456789012"]
          roleName: "aws-elasticbeanstalk-ec2-role"

files:
  "/tmp/beanstalk-database.json" :
    mode: "000644"
    owner: root
    group: root
    authentication: "S3Auth"
    source: https://s3-us-west-2.amazonaws.com/my-secret-bucket-123456789012/beanstalk-database.json

Guess you like

Origin www.cnblogs.com/cloudrivers/p/11258383.html