From e8e658bcead05ee9c5f819df60974ed0f9f4c64f Mon Sep 17 00:00:00 2001 From: scmacdon Date: Mon, 28 Oct 2024 12:10:41 -0400 Subject: [PATCH] updated the ACM Readme --- javav2/example_code/acm/README.md | 126 ++++++++++++++++++ .../main/java/com/example/acm/ImportCert.java | 8 +- .../acm/src/test/java/ACMTests.java | 102 ++++++++++++++ 3 files changed, 233 insertions(+), 3 deletions(-) create mode 100644 javav2/example_code/acm/README.md create mode 100644 javav2/example_code/acm/src/test/java/ACMTests.java diff --git a/javav2/example_code/acm/README.md b/javav2/example_code/acm/README.md new file mode 100644 index 00000000000..91c66ea73bd --- /dev/null +++ b/javav2/example_code/acm/README.md @@ -0,0 +1,126 @@ +# AWS Batch code examples for the SDK for Java 2.x + +## Overview + +Shows how to use the AWS SDK for Java 2.x to work with AWS Batch. + + + + +_AWS Batch enables you to run batch computing workloads on the AWS Cloud._ + +## ⚠ Important + +* Running this code might result in charges to your AWS account. For more details, see [AWS Pricing](https://aws.amazon.com/pricing/) and [Free Tier](https://aws.amazon.com/free/). +* Running the tests might result in charges to your AWS account. +* We recommend that you grant your code least privilege. At most, grant only the minimum permissions required to perform the task. For more information, see [Grant least privilege](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege). +* This code is not tested in every AWS Region. For more information, see [AWS Regional Services](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services). + + + + +## Code examples + +### Prerequisites + +For prerequisites, see the [README](../../README.md#Prerequisites) in the `javav2` folder. + + + + + +### Get started + +- [Hello AWS Batch](src/main/java/com/example/batch/HelloBatch.java#L6) (`listJobsPaginator`) + + +### Single actions + +Code excerpts that show you how to call individual service functions. + +- [CreateComputeEnvironment](src/main/java/com/example/batch/scenario/BatchActions.java#L102) +- [CreateJobQueue](src/main/java/com/example/batch/scenario/BatchActions.java#L193) +- [DeleteComputeEnvironment](src/main/java/com/example/batch/scenario/BatchActions.java#L142) +- [DeleteJobQueue](src/main/java/com/example/batch/scenario/BatchActions.java#L370) +- [DeregisterJobDefinition](src/main/java/com/example/batch/scenario/BatchActions.java#L323) +- [DescribeComputeEnvironments](src/main/java/com/example/batch/scenario/BatchActions.java#L162) +- [DescribeJobQueues](src/main/java/com/example/batch/scenario/BatchActions.java#L394) +- [DescribeJobs](src/main/java/com/example/batch/scenario/BatchActions.java#L490) +- [ListJobsPaginator](src/main/java/com/example/batch/scenario/BatchActions.java#L230) +- [RegisterJobDefinition](src/main/java/com/example/batch/scenario/BatchActions.java#L257) +- [SubmitJob](src/main/java/com/example/batch/scenario/BatchActions.java#L463) +- [UpdateComputeEnvironment](src/main/java/com/example/batch/scenario/BatchActions.java#L439) +- [UpdateJobQueue](src/main/java/com/example/batch/scenario/BatchActions.java#L347) + +### Scenarios + +Code examples that show you how to accomplish a specific task by calling multiple +functions within the same service. + +- [Learn AWS Batch core operations](src/main/java/com/example/batch/scenario/BatchScenario.java) + + + + + +## Run the examples + +### Instructions + + + + + +#### Hello AWS Batch + +This example shows you how to get started using AWS Batch. + + + +#### Learn AWS Batch core operations + +This example shows you how to do the following: + +- Create an AWS Batch compute environment. +- Check the status of the compute environment. +- Set up an AWS Batch job queue and job definition. +- Register a job definition. +- Submit an AWS Batch Job. +- Get a list of jobs applicable to the job queue. +- Check the status of job. +- Delete AWS Batch resources. + + + + + + + + +### Tests + +⚠ Running tests might result in charges to your AWS account. + + +To find instructions for running these tests, see the [README](../../README.md#Tests) +in the `javav2` folder. + + + + + + +## Additional resources + +- [AWS Batch User Guide](https://docs.aws.amazon.com/batch/latest/userguide/what-is-batch.html) +- [AWS Batch API Reference](https://docs.aws.amazon.com/batch/latest/APIReference/Welcome.html) +- [SDK for Java 2.x AWS Batch reference](https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/ec2/package-summary.html) + + + + +--- + +Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 \ No newline at end of file diff --git a/javav2/example_code/acm/src/main/java/com/example/acm/ImportCert.java b/javav2/example_code/acm/src/main/java/com/example/acm/ImportCert.java index 10412d98a21..bb69c094483 100644 --- a/javav2/example_code/acm/src/main/java/com/example/acm/ImportCert.java +++ b/javav2/example_code/acm/src/main/java/com/example/acm/ImportCert.java @@ -42,7 +42,8 @@ public static void main(String[] args) { String certificatePath = args[0]; String privateKeyPath = args[1]; - importCertificate(certificatePath, privateKeyPath); + String certificateArn = importCertificate(certificatePath, privateKeyPath); + System.out.println("Certificate imported with ARN: " + certificateArn); } /** @@ -53,7 +54,7 @@ public static void main(String[] args) { * @param privateKeyPath the file path to the private key associated with the certificate * @throws IOException if there is an error reading the certificate or private key files */ - public static void importCertificate(String certificatePath, String privateKeyPath) { + public static String importCertificate(String certificatePath, String privateKeyPath) { AcmClient acmClient = AcmClient.create(); try { byte[] certificateBytes = readFileBytes(certificatePath); @@ -66,10 +67,11 @@ public static void importCertificate(String certificatePath, String privateKeyPa ImportCertificateResponse response = acmClient.importCertificate(request); String certificateArn = response.certificateArn(); - System.out.println("Certificate imported with ARN: " + certificateArn); + return certificateArn; } catch (IOException e) { System.err.println("Error reading certificate or private key file: " + e.getMessage()); } + return ""; } private static byte[] readFileBytes(String filePath) throws IOException { diff --git a/javav2/example_code/acm/src/test/java/ACMTests.java b/javav2/example_code/acm/src/test/java/ACMTests.java new file mode 100644 index 00000000000..81437448bdc --- /dev/null +++ b/javav2/example_code/acm/src/test/java/ACMTests.java @@ -0,0 +1,102 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + + +import com.example.acm.AddTagsToCertificate; +import com.example.acm.DeleteCert; +import com.example.acm.DescribeCert; +import com.example.acm.ImportCert; +import com.example.acm.ListCertTags; +import com.example.acm.RemoveTagsFromCert; +import com.example.acm.RequestCert; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestMethodOrder; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +@TestInstance(TestInstance.Lifecycle.PER_METHOD) +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +public class ACMTests { + + private static String certificatePath = ""; + private static String privateKeyPath = ""; + + private static String certificateArn; + + @BeforeAll + public static void setUp() { + + certificatePath = "C:\\Users\\scmacdon\\cert_example\\certificate.pem"; + privateKeyPath = "C:\\Users\\scmacdon\\cert_example\\private_key.pem"; + } + + @Test + @Tag("IntegrationTest") + @Order(1) + public void testImportCert() { + assertDoesNotThrow(() -> { + certificateArn = ImportCert.importCertificate(certificatePath, privateKeyPath); + assertNotNull(certificateArn); + }); + } + + @Test + @Tag("IntegrationTest") + @Order(2) + public void testAddTags() { + assertDoesNotThrow(() -> { + AddTagsToCertificate.addTags(certificateArn); + }); + } + + @Test + @Tag("IntegrationTest") + @Order(3) + public void testDescribeCert() { + assertDoesNotThrow(() -> { + DescribeCert.describeCertificate(certificateArn); + }); + } + + @Test + @Tag("IntegrationTest") + @Order(4) + public void testListCertTags() { + assertDoesNotThrow(() -> { + ListCertTags.listCertTags(certificateArn); + }); + } + + @Test + @Tag("IntegrationTest") + @Order(5) + public void testRemoveTagsFromCert() { + assertDoesNotThrow(() -> { + RemoveTagsFromCert.removeTags(certificateArn); + }); + } + + + @Test + @Tag("IntegrationTest") + @Order(6) + public void testRequestCert() { + assertDoesNotThrow(() -> { + RequestCert.requestCertificate(); + }); + } + + @Test + @Tag("IntegrationTest") + @Order(7) + public void testDeleteCert() { + assertDoesNotThrow(() -> { + DeleteCert.deleteCertificate(certificateArn); + }); + } +}