Skip to content

Commit

Permalink
Java V2 Add the SSM Getting Started Scenario (awsdocs#6341)
Browse files Browse the repository at this point in the history
* added draft Eng spec for this getting started scenario
* added SSM Java getting started scenatio
* updated Java file to include another service operation
* added SSM Agent information to Java example
  • Loading branch information
scmacdon authored and DavidSouther committed Apr 30, 2024
1 parent 703b62d commit e90a59e
Show file tree
Hide file tree
Showing 12 changed files with 1,042 additions and 324 deletions.
158 changes: 147 additions & 11 deletions .doc_gen/metadata/ssm_metadata.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
# zexi 0.4.0
ssm_Hello:
title: Hello &SYS;
title_abbrev: Hello &SYS;
synopsis: get started using &SYS;.
category: Hello
languages:
Java:
versions:
- sdk_version: 2
github: javav2/example_code/ssm
sdkguide:
excerpts:
- description:
snippet_tags:
- ssm.java2.hello.main
services:
ssm: {listThings}
ssm_DescribeParameters:
title: Get information about &SYS; parameters using an &AWS; SDK
title_abbrev: Get parameters information
Expand Down Expand Up @@ -49,10 +66,10 @@ ssm_PutParameter:
- ssm.rust.create-parameter
services:
ssm: {PutParameter}
ssm_CreateOpsItem:
title: Create a new OpsItem using an &AWS; SDK
title_abbrev: Create a new OpsItem
synopsis: create a new OpsItem.
ssm_createOpsItem:
title: Create an opsItem using the &SYS; SDK
title_abbrev: Create an opsItem
synopsis: create an opsItem.
category:
languages:
Java:
Expand All @@ -66,10 +83,78 @@ ssm_CreateOpsItem:
- ssm.java2.create_ops.main
services:
ssm: {CreateOpsItem}
ssm_DescribeOpsItems:
title: Describe an OpsItem using an &AWS; SDK
title_abbrev: Describe an OpsItem
synopsis: describe an OpsItem.
ssm_updateMaintenanceWindow:
title: Update a maintenance window using the &SYS; SDK
title_abbrev: Update a maintenance window
synopsis: update a maintenance window.
category:
languages:
Java:
versions:
- sdk_version: 2
github: javav2/example_code/ssm
sdkguide:
excerpts:
- description:
snippet_tags:
- ssm.java2.update_window.main
services:
ssm: {UpdateMaintenanceWindow}
ssm_createMaintenanceWindow:
title: Create a maintenance window using the &SYS; SDK
title_abbrev: Create a maintenance window
synopsis: create a maintenance window.
category:
languages:
Java:
versions:
- sdk_version: 2
github: javav2/example_code/ssm
sdkguide:
excerpts:
- description:
snippet_tags:
- ssm.java2.create_window.main
services:
ssm: {CreateMaintenanceWindow}
ssm_sendCommand:
title: Send a command using the &SYS; SDK
title_abbrev: Send a command
synopsis: send a command.
category:
languages:
Java:
versions:
- sdk_version: 2
github: javav2/example_code/ssm
sdkguide:
excerpts:
- description:
snippet_tags:
- ssm.Java2.send_command.main
services:
ssm: {SendCommand}
ssm_createDocument:
title: Create a document using the &SYS; SDK
title_abbrev: Create a document
synopsis: create a document.
category:
languages:
Java:
versions:
- sdk_version: 2
github: javav2/example_code/ssm
sdkguide:
excerpts:
- description:
snippet_tags:
- ssm.java2.create_doc.main
services:
ssm: {CreateDocument}
ssm_describeOpsItems:
title: Describe an &SYS; Opsitem using the SDK
title_abbrev: Describe an Opsitem
synopsis: describe an Opsitem.
category:
languages:
Java:
Expand All @@ -82,10 +167,44 @@ ssm_DescribeOpsItems:
snippet_tags:
- ssm.java2.describe_ops.main
services:
ssm: {DescribeOpsItems}
ssm: {DescribeOpsItems}
ssm_deleteMaintenanceWindow:
title: Delete a maintenance window using the &SYS; SDK
title_abbrev: Delete a maintenance window
synopsis: delete a maintenance window.
category:
languages:
Java:
versions:
- sdk_version: 2
github: javav2/example_code/ssm
sdkguide:
excerpts:
- description:
snippet_tags:
- ssm.java2.delete_window.main
services:
ssm: {DeleteMaintenanceWindow}
ssm_deleteDocument:
title: Delete a document using the &SYS; SDK
title_abbrev: Delete a document
synopsis: delete a document.
category:
languages:
Java:
versions:
- sdk_version: 2
github: javav2/example_code/ssm
sdkguide:
excerpts:
- description:
snippet_tags:
- ssm.Java2.delete_doc.main
services:
ssm: {DeleteDocument}
ssm_UpdateOpsItem:
title: Updates an OpsItem using an &AWS; SDK
title_abbrev: Updates an OpsItem
title: Update an OpsItem using a &SYS; SDK
title_abbrev: Update an OpsItem
synopsis: updates an OpsItem.
category:
languages:
Expand All @@ -100,3 +219,20 @@ ssm_UpdateOpsItem:
- ssm.Java2.resolve_ops.main
services:
ssm: {UpdateOpsItem}
ssm_Scenario:
title: Get started with &SYS; using an &AWS; SDK
title_abbrev: Get started with &SYS;
synopsis: work with &SYS; maintenance windows, documents, and OpsItems.
category: Scenarios
languages:
Java:
versions:
- sdk_version: 2
github: javav2/example_code/ssm
sdkguide:
excerpts:
- description:
snippet_tags:
- ssm.java2.scenario.main
services:
ssm: {CreateOpsItem, CreateMaintenanceWindow, CreateDocument, SendCommand, CommandInvocations, DeleteMaintenanceWindow, UpdateOpsItem}
45 changes: 45 additions & 0 deletions getting_started_scenarios/ssm_scenario/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# AWS Systems Management Getting Started Scenario

## Introduction
This AWS Systems Manager getting started scenario demonstrates how to interact with the AWS Systems Manager service using an AWS SDK. The scenario covers various operations such as creating a maintenance window, creating an SSM document, sending a command to a managed node, creating an OpsItem, updating an OpsItem, and deleting SSM resources.

## Setting up Resources
AWS Systems Manager Agent is Amazon software that runs on Amazon Elastic Compute Cloud (Amazon EC2) instances, edge devices, on-premises servers, and virtual machines (VMs). A Systems Manager Agent makes it possible for Systems Manager to update, manage, and configure these resources. To successfully run this getting started scenario, the EC2 instance must have a Systems Manager Agent. For more information, see [Working with SSM Agent](https://docs.aws.amazon.com/systems-manager/latest/userguide/ssm-agent.html).

## Service Operations Invoked
The program performs the following tasks:

1. Creates a Systems Manager maintenance window.
2. Modifies the maintenance window by changing the schedule.
3. Creates a Systems Manager document that defines the actions Systems Manager performs on managed nodes.
4. Sends a command to an EC2 instance using the created Systems Manager document.
5. Retrieves the time when the specific command was sent to the managed node.
6. Creates a Systems Manager OpsItem to track and manage an operational issue.
7. Updates the created OpsItem and gets the status.
8. Resolves the OpsItem.
9. Optionally deletes the Systems Manager resources (maintenance window, OpsItem, and document).

## Usage
1. Clone the repository or download the source code.
2. Open the code in your preferred IDE.
3. This scenario requires the following variables:
- `instanceId`: The ID of the EC2 instance to send the command to.
- `title`: The title of the OpsItem to create.
- `source`: The source of the OpsItem.
- `category`: The category of the OpsItem.
- `severity`: The severity of the OpsItem.
4. Run the `SSMScenario` class.

The program will guide you through the scenario, prompting you to enter the maintenance window name and the document name. The program will also display the progress and results of the various operations.

## Code Explanation
The provided code demonstrates the following key features of the AWS SDK and the AWS Systems Manager service:

1. **Maintenance Window Management**: The code uses the `SsmClient` to create, modify, and delete an SSM maintenance window.
2. **SSM Document Management**: The code creates an SSM document that defines the actions Systems Manager performs on managed nodes.
3. **Command Execution**: The code sends a command to an EC2 instance using the created SSM document and retrieves the timestamp of the command execution.
4. **OpsItem Management**: The code creates, updates, and resolves an SSM OpsItem to track and manage an operational issue.
5. **Error Handling**: The code includes exception handling for various SSM-related exceptions.
6. **User Interaction**: The code prompts the user for input, such as the maintenance window name and the document name.

Overall, this AWS SDK Systems Manager code example is a resource for developers new to AWS Systems Manager and the AWS SDK. It provides a solid foundation for understanding and building applications that interact with the AWS Systems Manager service.
121 changes: 121 additions & 0 deletions getting_started_scenarios/ssm_scenario/SPECIFICATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# AWS Systems Manager Engineering Specification

## Overview
This SDK getting started scenario demonstrates how to interact with AWS Systems Manager using an AWS SDK. The provided code is an AWS application that demonstrates the usage of the AWS Systems Manager SDK to interact with various AWS Systems Manager service operations.

## Scenario Program Flow
- Creates a Systems Manager maintenance window with a default name or a user-provided name.
- Modifies the maintenance window schedule.
- Creates a Systems Manager document with a default name or a user-provided name.
- Sends a command to a specified EC2 instance using the created document and display the time when the command was invoked.
- Creates a Systems Manager OpsItem with a predefined title, source, category, and severity.
- Updates and resolves the created OpsItem.
- Deletes the Systems Manager maintenance window, OpsItem, and document.

## Hello SSM
This program is intended for users not familiar with Systems Manager SDK to easily get up and running. The logic is to show use of listDocumentsPaginator().

### Program execution
The following shows the output of the program in the console.

```
Document Name: AWSMigration-ConvertCentOsToRockyLinuxDistribution
Document Name: AWSMigration-CreateLoadBalanceAutoScaleGroup
Document Name: AWSMigration-EnableInspector
```


## Scenario Program execution
The following shows the output of the program in the console.


```
--------------------------------------------------------------------------------
Welcome to the AWS Systems Manager SDK Getting Started scenario.
This Java program demonstrates how to interact with AWS Systems Manager using the AWS SDK.
AWS Systems Manager is the operations hub for your AWS applications and resources and a secure end-to-end management solution.
The program's primary functionalities include creating a maintenance window, creating a document, sending a command to a document,
listing documents, listing commands, creating an OpsItem, modifying an OpsItem, and deleting AWS SSM resources.
Upon completion of the program, all AWS resources are cleaned up.
Let's get started...
Please hit Enter
--------------------------------------------------------------------------------
Create an SSM maintenance window.
Please enter the maintenance window name (default is ssm-maintenance-window):
The maintenance window id is mw-0a782f69416fa2d68
--------------------------------------------------------------------------------
Modify the maintenance window by changing the schedule
Please hit Enter
The SSM maintenance window was successfully updated
--------------------------------------------------------------------------------
Create an SSM document that defines the actions that Systems Manager performs on your managed nodes.
Please enter the document name (default is ssmdocument):
The status of the SSM document is Creating
--------------------------------------------------------------------------------
Now we are going to run a command on an EC2 instance
Please hit Enter
The SSM document is active and ready to use.
Command ID: ac4aef03-7d60-4fba-8d71-051defea89e2
Wait 5 secs
Command execution successful
--------------------------------------------------------------------------------
Lets get the time when the specific command was sent to the specific managed node
Please hit Enter
The time of the command invocation is 2024-04-09 14:52:50
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Now we will create an SSM OpsItem.
SSM OpsItem is a feature provided by the Systems Manager service.
It is a type of operational data item that allows you to manage and track various operational issues,
events, or tasks within your AWS environment.
You can create OpsItems to track and manage operational issues as they arise.
For example, you could create an OpsItem whenever your application detects a critical error
or an anomaly in your infrastructure.
Please hit Enter
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Now we will update SSM OpsItem oi-c1e5435471e9
Please hit Enter
Now we will resolve the SSM OpsItem oi-c1e5435471e9
Please hit Enter
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Would you like to delete the AWS Systems Manager resources? (y/n)
The AWS Systems Manager resources will not be deleted
--------------------------------------------------------------------------------
This concludes the AWS Systems Manager SDK Getting Started scenario.
--------------------------------------------------------------------------------
```
```
## Metadata
The following table describes the metadata used in this SDK Getting Started Scenario.
| action | metadata file | metadata key |
|------------------------------|------------------------------|---------------------------------------- |
| `CreateOpsItem` | ssm_metadata.yaml | ssm_CreateOpsItem |
| `CreateMaintenanceWindow` | ssm_metadata.yaml | ssm_CreateMainWindow |
| `UpdateMaintenanceWindow` | ssm_metadata.yaml | ssm_UpdateMainWindow |
| `CreateDocument` | ssm_metadata.yaml | ssm_CreateDocument |
| `SendCommand ` | ssm_metadata.yaml | ssm_SendCommand |
| `CommandInvocations` | ssm_metadata.yaml | ssm_DescribeInvocation |
| `UpdateOpsItem` | ssm_metadata.yaml | ssm_UpdateOpsItem |
| `DeleteMaintenanceWindow ` | ssm_metadata.yaml | ssm_DeleteMainWindow |
| `DeleteDocument` | ssm_metadata.yaml | ssm_DeleteMainWindow |
| `DescribeOpsItems ` | ssm_metadata.yaml | ssm_DescribeOpsItems |
5 changes: 5 additions & 0 deletions javav2/example_code/sns/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@
<version>5.9.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>software.amazon.sns</groupId>
<artifactId>sns-extended-client</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-commons</artifactId>
Expand Down
Loading

0 comments on commit e90a59e

Please sign in to comment.