Tagebextensions

AWS Elastic Beanstalk how to access to the RDS environment variables under ebextensions and postdeploy hooks

facebooktwittergoogle_pluslinkedinmailby feather

As a beginning, just to let you know, it is now my 54th deployment (which means around a week) using ebextensions in order to reverse engineering how it works in terms of environment variables!

The RDS environment variables are:

- RDS_USERNAME

- RDS_PASSWORD

- RDS_HOSTNAME

- RDS_DB_ NAME

The weird part is, accessing to those environment variables under the following 3 scenarios are different:

1. Directly under ebextensions : This is not possible !

2. Under the scripts triggered by ebextensions : This is possible, you can use them like $RDS_HOSTNAME …

3. Under the hooks  : This was not possible but here is the workaround that i found and worked for my case:

– Store them under a file using a script trigged by ebextensions:

echo RDS_HOSTNAME=$RDS_HOSTNAME >> /etc/environment
echo RDS_USERNAME=$RDS_USERNAME >> /etc/environment
echo RDS_PASSWORD=$RDS_PASSWORD >> /etc/environment

– Parse them from the hook:

RDS_HOSTNAME="$(awk -F= '/RDS_HOSTNAME/{print $2}' /etc/environment)"
RDS_USERNAME="$(awk -F= '/RDS_USERNAME/{print $2}' /etc/environment)"
RDS_PASSWORD="$(awk -F= '/RDS_PASSWORD/{print $2}' /etc/environment)"

What a nasty solution but works!

 

AWS Elastic Beanstalk ebextensions Security Group firewall rules

facebooktwittergoogle_pluslinkedinmailby feather

In order to define the firewall rules of the Security Group that the instance will belong to, you need to define the “Resources” like as the following:

Resources:

  AWSEBSecurityGroup:

    Type: “AWS::EC2::SecurityGroup”

    Properties:

      GroupDescription: “Security group to allow HTTP, HTTPS,SSH”

      SecurityGroupIngress:

        - {CidrIp: “0.0.0.0/0″, IpProtocol: “tcp“, FromPort: “8080”, ToPort: “8080”}

        - {CidrIp: “0.0.0.0/0″, IpProtocol: “tcp“, FromPort: “8443”, ToPort: “8443”}

        - {CidrIp: “0.0.0.0/0″, IpProtocol: “tcp“, FromPort: “443”, ToPort: “443”}

        - {CidrIp: “0.0.0.0/0″, IpProtocol: “tcp“, FromPort: “80”, ToPort: “80”}

        - {CidrIp: “0.0.0.0/0″, IpProtocol: “tcp“, FromPort: “22”, ToPort: “22”}

Save the “resources.config” under “.ebextensions” folder and deploy!

      

© 2017 Derya Sezen

Theme by Anders NorenUp ↑


visited 27 states (12%)
Create your own visited map of The World