|
1 |
| -//snippet-sourcedescription:[CreateApplication.java demonstrates how to create an application.] |
2 |
| -//snippet-keyword:[Java] |
3 |
| -//snippet-keyword:[Code Sample] |
4 |
| -//snippet-keyword:[AWS CodeDeploy |
5 |
| -//snippet-service:[AWS CodeDeploy] |
6 |
| -//snippet-sourcetype:[full-example] |
7 |
| -//snippet-sourcedate:[10/3/2020] |
8 |
| -//snippet-sourceauthor:[scmacdon AWS] |
9 |
| - |
10 |
| -/* |
11 |
| - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
12 |
| - * |
13 |
| - * Licensed under the Apache License, Version 2.0 (the "License"). |
14 |
| - * You may not use this file except in compliance with the License. |
15 |
| - * A copy of the License is located at |
16 |
| - * |
17 |
| - * http://aws.amazon.com/apache2.0 |
18 |
| - * |
19 |
| - * or in the "license" file accompanying this file. This file is distributed |
20 |
| - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
21 |
| - * express or implied. See the License for the specific language governing |
22 |
| - * permissions and limitations under the License. |
23 |
| - */ |
24 |
| -package com.example.deploy; |
25 |
| - |
26 |
| -// snippet-start:[codedeploy.java2.create_app.import] |
27 |
| -import software.amazon.awssdk.regions.Region; |
28 |
| -import software.amazon.awssdk.services.codedeploy.CodeDeployClient; |
29 |
| -import software.amazon.awssdk.services.codedeploy.model.CodeDeployException; |
30 |
| -import software.amazon.awssdk.services.codedeploy.model.ComputePlatform; |
31 |
| -import software.amazon.awssdk.services.codedeploy.model.CreateApplicationRequest; |
32 |
| -import software.amazon.awssdk.services.codedeploy.model.CreateApplicationResponse; |
33 |
| -// snippet-end:[codedeploy.java2.create_app.import] |
34 |
| - |
35 |
| -public class CreateApplication { |
36 |
| - |
37 |
| - public static void main(String[] args) { |
38 |
| - |
39 |
| - final String USAGE = "\n" + |
40 |
| - "Usage:\n" + |
41 |
| - " CreateApplication <appName> \n\n" + |
42 |
| - "Where:\n" + |
43 |
| - " appName - the name of the application \n"; |
44 |
| - |
45 |
| - if (args.length < 1) { |
46 |
| - System.out.println(USAGE); |
47 |
| - System.exit(1); |
48 |
| - } |
49 |
| - |
50 |
| - /* Read the name from command args*/ |
51 |
| - String appName = args[0]; |
52 |
| - |
53 |
| - Region region = Region.US_EAST_1; |
54 |
| - CodeDeployClient deployClient = CodeDeployClient.builder() |
55 |
| - .region(region) |
56 |
| - .build(); |
57 |
| - |
58 |
| - // Create the application |
59 |
| - createApp(deployClient, appName); |
60 |
| - } |
61 |
| - |
62 |
| - // snippet-start:[codedeploy.java2.create_app.main] |
63 |
| - public static void createApp(CodeDeployClient deployClient, String appName) { |
64 |
| - try { |
65 |
| - CreateApplicationRequest applicationRequest = CreateApplicationRequest.builder() |
66 |
| - .applicationName(appName) |
67 |
| - .computePlatform(ComputePlatform.SERVER) |
68 |
| - .build(); |
69 |
| - |
70 |
| - CreateApplicationResponse applicationResponse = deployClient.createApplication(applicationRequest); |
71 |
| - String appId = applicationResponse.applicationId(); |
72 |
| - System.out.println("The application ID is "+appId); |
73 |
| - |
74 |
| - } catch (CodeDeployException e) { |
75 |
| - System.err.println(e.awsErrorDetails().errorMessage()); |
76 |
| - System.exit(1); |
77 |
| - } |
78 |
| - } |
79 |
| - // snippet-end:[codedeploy.java2.create_app.main] |
80 |
| -} |
| 1 | +//snippet-sourcedescription:[CreateApplication.java demonstrates how to create an application.] |
| 2 | +//snippet-keyword:[AWS SDK for Java v2] |
| 3 | +//snippet-keyword:[Code Sample] |
| 4 | +//snippet-keyword:[AWS CodeDeploy |
| 5 | +//snippet-sourcetype:[full-example] |
| 6 | +//snippet-sourcedate:[11/3/2020] |
| 7 | +//snippet-sourceauthor:[scmacdon AWS] |
| 8 | + |
| 9 | +/* |
| 10 | + Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 11 | + SPDX-License-Identifier: Apache-2.0 |
| 12 | +*/ |
| 13 | +package com.example.deploy; |
| 14 | + |
| 15 | +// snippet-start:[codedeploy.java2.create_app.import] |
| 16 | +import software.amazon.awssdk.regions.Region; |
| 17 | +import software.amazon.awssdk.services.codedeploy.CodeDeployClient; |
| 18 | +import software.amazon.awssdk.services.codedeploy.model.CodeDeployException; |
| 19 | +import software.amazon.awssdk.services.codedeploy.model.ComputePlatform; |
| 20 | +import software.amazon.awssdk.services.codedeploy.model.CreateApplicationRequest; |
| 21 | +import software.amazon.awssdk.services.codedeploy.model.CreateApplicationResponse; |
| 22 | +// snippet-end:[codedeploy.java2.create_app.import] |
| 23 | + |
| 24 | +public class CreateApplication { |
| 25 | + |
| 26 | + public static void main(String[] args) { |
| 27 | + |
| 28 | + final String USAGE = "\n" + |
| 29 | + "Usage:\n" + |
| 30 | + " CreateApplication <appName> \n\n" + |
| 31 | + "Where:\n" + |
| 32 | + " appName - the name of the application. \n"; |
| 33 | + |
| 34 | + if (args.length != 1) { |
| 35 | + System.out.println(USAGE); |
| 36 | + System.exit(1); |
| 37 | + } |
| 38 | + |
| 39 | + String appName = args[0]; |
| 40 | + Region region = Region.US_EAST_1; |
| 41 | + CodeDeployClient deployClient = CodeDeployClient.builder() |
| 42 | + .region(region) |
| 43 | + .build(); |
| 44 | + |
| 45 | + createApp(deployClient, appName); |
| 46 | + deployClient.close(); |
| 47 | + } |
| 48 | + |
| 49 | + // snippet-start:[codedeploy.java2.create_app.main] |
| 50 | + public static void createApp(CodeDeployClient deployClient, String appName) { |
| 51 | + try { |
| 52 | + CreateApplicationRequest applicationRequest = CreateApplicationRequest.builder() |
| 53 | + .applicationName(appName) |
| 54 | + .computePlatform(ComputePlatform.SERVER) |
| 55 | + .build(); |
| 56 | + |
| 57 | + CreateApplicationResponse applicationResponse = deployClient.createApplication(applicationRequest); |
| 58 | + String appId = applicationResponse.applicationId(); |
| 59 | + System.out.println("The application ID is "+appId); |
| 60 | + |
| 61 | + } catch (CodeDeployException e) { |
| 62 | + System.err.println(e.awsErrorDetails().errorMessage()); |
| 63 | + System.exit(1); |
| 64 | + } |
| 65 | + } |
| 66 | + // snippet-end:[codedeploy.java2.create_app.main] |
| 67 | +} |
0 commit comments