简体   繁体   中英

EC2 Pass Environment Variables Via "runInstance" to Docker without overriding UserData

I have a launch template (CloudFormation) and a Java App using the SDK. The launch template includes UserData for retrieving and starting a Docker container, but said container expects some environment variables. These I plan on sending alongside with the runInstanceRequest from the Java SDK, but cannot use the UserData for transmission. Any idea on how this scenario can be resolved?

I don't know if this is the best solution, but it is at least one (I think)

GetLaunchTemplateDataRequest.Builder userDataRequest = GetLaunchTemplateDataRequest.builder();
userDataRequest.instanceId(getTemplateArnOf(type));
GetLaunchTemplateDataResponse userDataResponse = EC2_CLIENT.getLaunchTemplateData(userDataRequest.build());
String userData = userDataResponse.launchTemplateData().userData();

Then modify userData to incorporate the environment variables and add to RunInstanceRequest

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM