forked from awsdocs/aws-doc-sdk-examples
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Java V2 Add the SSM Getting Started Scenario (awsdocs#6341)
* 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
1 parent
703b62d
commit e90a59e
Showing
12 changed files
with
1,042 additions
and
324 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
121
getting_started_scenarios/ssm_scenario/SPECIFICATION.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.