Dynamic values in .ebextenstions based on prod vs nonProd deployment for Elastic Beanstalk Linux 2

23 Views Asked by At

I am trying to dynamically get key values in my Elastic Beanstalk deployment so I can have one build that will work in nonProd and Prod. May current approach is to build with a nonProd config file. Then when I am ready to go to Production, switch out config files and build again. This is a terrible approach. I want to do one build that I can deploy to both. I have tried at least 100 ways and can't figure it out. Here is my latest approach in my config located in .ebextensions. file name: aa_config_file.config

Just to be clear. Everything worked fine before I tried to do this dynamically. So it is just this one config file that is causing me issue.

At one point, I was writing the Account Id to a tmp file. That worked. But then, like now, I can't figure out how to get the option_settings to use it.

command: |
  CURRENT_ACCOUNT_ID=$(aws sts get-caller-identity --query 'Account' --output text)
  PRODUCTION_ACCOUNT_ID="22222"

  if [ "$CURRENT_ACCOUNT_ID" == "$PRODUCTION_ACCOUNT_ID" ]; then
    export SSLCertificateArns='arn:aws:acm:us-east-1:22222:certificate/dddd'
    export ManagedSecurityGroup="sg-4545"
    export SecurityGroups="sg-4545"
  else
    export SSLCertificateArns='arn:aws:acm:us-east-1:4444:certificate/77777'
    export ManagedSecurityGroup="sg-2222"
    export SecurityGroups="sg-222"
  fi


option_settings:
  aws:elbv2:listener:443:
    ListenerEnabled: 'true'
    Protocol: HTTPS
    Rules: admin
    SSLCertificateArns: "$SSLCertificateArns"
    SSLPolicy: ELBSecurityPolicy-TLS-1-2-Ext-2018-06
  aws:elbv2:loadbalancer:
    ManagedSecurityGroup: "$ManagedSecurityGroup"
    SecurityGroups: "$SecurityGroups"
  aws:elasticbeanstalk:environment:process:https:
    Port: '443'
    Protocol: HTTPS
  aws:elasticbeanstalk:environment:process:admin:
    HealthCheckPath: /services/bsemail/ems/test
    Port: '443'
    Protocol: HTTPS
  aws:elbv2:listenerrule:admin:
    PathPatterns: /*
    Priority: 1
    Process: admin
0

There are 0 best solutions below