RunInstancesRequest
用于创建实例的 API 在我用来启动数据的类上具有以下可用方法:
公共无效 setUserData(字符串用户数据)
这完全涵盖了@birryee 在用户指南中所说的内容。
因此,我的示例应用程序使用以下 Java 代码来启动项目:
// create the actual request
RunInstancesRequest request = new RunInstancesRequest();
request.withMinCount(1).withMaxCount(count);
request.withKeyName("TheOwner");
request.withSecurityGroups("SSH");
request.withInstanceType(InstanceType.T2Micro);
request.withImageId("MyImageID");
request.withRegion(Region.getRegion(Regions.US_EAST_1));
// add a web hook call to notify us when the instance is launched
request.withUserData("#!/bin/bash\ncurl -X POST http://domain.com/email-me");
// launch it
RunInstancesResult awsResponse = awsClient.runInstances(request);