Skip to content

Commit

Permalink
updated the ACM Readme
Browse files Browse the repository at this point in the history
  • Loading branch information
scmacdon committed Oct 28, 2024
1 parent 24bb6ac commit e8e658b
Show file tree
Hide file tree
Showing 3 changed files with 233 additions and 3 deletions.
126 changes: 126 additions & 0 deletions javav2/example_code/acm/README.md
Original file line number Diff line number Diff line change
@@ -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.

<!--custom.overview.start-->
<!--custom.overview.end-->

_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).

<!--custom.important.start-->
<!--custom.important.end-->

## Code examples

### Prerequisites

For prerequisites, see the [README](../../README.md#Prerequisites) in the `javav2` folder.


<!--custom.prerequisites.start-->
<!--custom.prerequisites.end-->

### 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)


<!--custom.examples.start-->
<!--custom.examples.end-->

## Run the examples

### Instructions


<!--custom.instructions.start-->
<!--custom.instructions.end-->

#### 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.

<!--custom.scenario_prereqs.batch_Scenario.start-->
<!--custom.scenario_prereqs.batch_Scenario.end-->


<!--custom.scenarios.batch_Scenario.start-->
<!--custom.scenarios.batch_Scenario.end-->

### 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.



<!--custom.tests.start-->
<!--custom.tests.end-->

## 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)

<!--custom.resources.start-->
<!--custom.resources.end-->

---

Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

SPDX-License-Identifier: Apache-2.0
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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);
Expand All @@ -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 {
Expand Down
102 changes: 102 additions & 0 deletions javav2/example_code/acm/src/test/java/ACMTests.java
Original file line number Diff line number Diff line change
@@ -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);
});
}
}

0 comments on commit e8e658b

Please sign in to comment.