AWS ๋น์คํก์ ์ด์ฉํ์ฌ ์ธ์คํด์ค๋ฅผ ์ฌ๋ฌ๊ฐ ๋์ฐ๊ณ
๋ถ์ฐ์์คํ ํ๊ฒฝ์ ๋ง๋ค์ด ๊ฐ๋ฐ์ ํ ๋
๊ฐ ๋น์คํก ์ธ์คํด์ค์ private IP๊ฐ ํ์ํ ๊ฒฝ์ฐ
AWS SDK๋ฅผ ์ด์ฉํ์ฌ ์๋์ ๊ฐ์ด ๊ตฌํ์ ํ ์ ์๋ค.
public List<String> getBeanstalkIps() {
return findIpsByIds(findIds(getBeanstalkResources()));
}
private DescribeEnvironmentResourcesResult getBeanstalkResources() {
DescribeEnvironmentResourcesRequest request =
new DescribeEnvironmentResourcesRequest()
.withEnvironmentName("my-beanstalk-app");
return beanstalk.describeEnvironmentResources(request);
}
private List<String> findIds(DescribeEnvironmentResourcesResult resources) {
return resources.getEnvironmentResources().getInstances().stream()
.map(Instance::getId)
.collect(toList());
}
private List<String> findIpsByIds(List<String> ids) {
DescribeInstancesRequest request =
new DescribeInstancesRequest().withInstanceIds(ids);
DescribeInstancesResult result = ec2.describeInstances(request);
return result.getReservations().stream()
.flatMap(n -> n.getInstances().stream())
.map(com.amazonaws.services.ec2.model.Instance::getPrivateIpAddress)
.sorted()
.collect(toList());
}
์ฌ๊ธฐ์ ํ์ํ ๊ฒ์ "my-beanstalk-app"์ ๋์ฒดํ ๋น์คํก ํ๊ฒฝ๋ช ์ธ๋ฐ
์ด ์ด๋ฆ์ AWS Console > Elastic Beanstalk > (์ ํ๋ฆฌ์ผ์ด์ ) > Environment ์์ ํ์ธ์ด ๊ฐ๋ฅํ๋ค.
AWS SDK๋ 2018๋ 11์ 2.x ๋ฒ์ ์ด ๋์์ผ๋ ์์ง 1.11 ๋ฒ์ ์ ์ฌ์ฉ ์ค์ด๋ค.
SDK 2.x๋ก ๊ตฌํ์์๋ ์๋์ ๊ฐ์ด ํ ์ ์๋ค.
-- TODO --