How to auto create a Classic Link for AWS EB Insta

2019-08-08 06:14发布

I have a Classic app on EB that needs to connect to RDS in a VPC.

I can manually configure the EB instances to allow a Classic Link to the VPC by going into EC2 - Instance - Actions - ClassicLink - Link to VPC. Once I do this all is fine BUT this won't auto-link new instances without manual intervention.

I know I need to move the EB app to be within the VPC but I was wondering if I could set EB to auto-create a Classic Link for new instances within EB?

I would have thought I could edit the config/yml files to pre-configure new instances but haven't found any reference to this.

Does anyone know if this is possible and if so how to do it?

Thanks!

2条回答
The star\"
2楼-- · 2019-08-08 06:51

I was wondering if I could set EB to auto-create a Classic Link for new instances within EB

Yes - you can link an EC2-Classic instance to a ClassicLink-enabled VPC with the attach-classic-link-vpc command. Refer to EB-CLI, PowerShell, or EC2API reference documentation for a guide to it within each language.

My recommendation would be to use the EC2API if you want the instance to do it automatically upon creation. Query and get the instance ids and vpc ids via the metadata calls. Then use the ids in the EC2API call.

Does anyone know if this is possible and if so how to do it?

Check the example at the bottom of the EC2API attach-classic-link-vpc page or another example found at this site. The later has you grant permission to run this command via Identity and Access Management first.

Other classiclink api calls can be found here in case you need to classiclink enable your VPC or perform other common classiclink tasks.

Take a run at it and give it a go. If you get stuck, create a new question with exact particulars and as much configuration/diagnostic info as you can post and we can try and help you get through it.

查看更多
孤傲高冷的网名
3楼-- · 2019-08-08 06:58

I was able to do it using this script (set CLASSIC_LINK_GROUPS in your EB environment variables so that you can change the groups you use per environment):

# Enable ClassicLink on the new instance (so it can connect to VPC resources)
commands:
  "Link to VPC":
    command: >
      aws ec2 attach-classic-link-vpc
      --instance-id `wget -q -O - http://169.254.169.254/latest/meta-data/instance-id`
      --vpc-id vpc-XXX
      --groups `sudo /opt/elasticbeanstalk/bin/get-config environment -k CLASSIC_LINK_GROUPS`
      --region us-west-2

Save this as 00_classic_link.config in your .ebextensions folder.

查看更多
登录 后发表回答