|
| 1 | +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
1 | 4 | package com.example.ec2; |
2 | 5 |
|
3 | 6 | import software.amazon.awssdk.regions.Region; |
|
11 | 14 | public class CreateLaunchTemplate { |
12 | 15 |
|
13 | 16 | public static void main(String[] args) { |
14 | | - String groupName = "ScottASG606" ; //rgs[0]; |
15 | | - String launchTemplateName = "MyTemplate5" ;//args[1]; |
16 | | - String vpcZoneId = "subnet-0ddc451b8a8a1aa44" ; //args[2]; |
17 | | - String instanceType= "t2.2xlarge" ; |
18 | | - String imageId = "ami-0f6832b69407e9746" ; |
19 | | - String keyName = "TestKeyPair"; |
| 17 | + final String usage = """ |
| 18 | + Usage: |
| 19 | + <launchTemplateName> <instanceType> <imageId> <keyName> |
| 20 | + |
| 21 | + Where: |
| 22 | + launchTemplateName - The name of the launch template to create. |
| 23 | + instanceType - The EC2 instance type (e.g., t2.2xlarge). |
| 24 | + imageId - The AMI ID for the instance (e.g., ami-0f6832b69407e9746). |
| 25 | + keyName - The name of the key pair for SSH access. |
| 26 | + """; |
| 27 | + |
| 28 | + if (args.length != 4) { |
| 29 | + System.out.println(usage); |
| 30 | + System.exit(1); |
| 31 | + } |
| 32 | + |
| 33 | + String launchTemplateName = args[0]; |
| 34 | + String instanceType = args[1]; |
| 35 | + String imageId = args[2]; |
| 36 | + String keyName = args[3]; |
20 | 37 |
|
21 | 38 | Ec2Client ec2 = Ec2Client.builder() |
22 | 39 | .region(Region.US_EAST_1) |
23 | 40 | .build(); |
24 | 41 |
|
25 | 42 | createLaunchTemplate(ec2, launchTemplateName, instanceType, imageId, keyName); |
26 | 43 | } |
| 44 | + |
27 | 45 | public static void createLaunchTemplate(Ec2Client ec2, String launchTemplateName, String instanceType, String imageId, String keyName) { |
28 | 46 | try { |
29 | 47 | RequestLaunchTemplateData launchTemplateData = RequestLaunchTemplateData.builder() |
|
0 commit comments