Automatically create an RFC in AMS using Python
Created by Gnanasekaran Kailasam (AWS)
Summary
AWS Managed Services (AMS) helps you to operate your cloud-based infrastructure more efficiently and securely by providing ongoing management of your Amazon Web Services (AWS) infrastructure. To make a change to your managed environment, you need to create and submit a new request for change (RFC) that includes a change type (CT) ID for a particular operation or action.
However, manually creating an RFC can take around five minutes and teams in your organization might need to submit multiple RFCs every day. This pattern helps you to automate the RFC creation process, reduce the creation time for each RFC, and eliminate manual errors.
This pattern describes how to use Python code to automatically create the Stop EC2 instance
RFC that stops Amazon Elastic Compute Cloud (Amazon EC2) instances in your AMS account. You can then apply this pattern’s approach and the Python automation to other RFC types.
Prerequisites and limitations
Prerequisites
An AMS Advanced account. For more information about this, see AMS operations plans in the AWS Managed Services documentation.
At least one existing EC2 instance in your AMS account.
An understanding of how to create and submit RFCs in AMS.
Familiarity with Python.
Limitations
You can only use RFCs for changes in your AMS account. Your AWS account uses different processes for similar changes.
Architecture
Technology stack
AMS
AWS Command Line Interface (AWS CLI)
AWS SDK for Python (Boto3)
Python and its required packages (JSON and Boto3)
Automation and scale
This pattern provides sample code to automate the Stop EC2 instance
RFC, but you can use this pattern’s sample code and approach for other RFCs.
Tools
AWS Managed Services – AMS helps you to operate your AWS infrastructure more efficiently and securely.
AWS CLI – AWS Command Line Interface (AWS CLI) is a unified tool to manage your AWS services. In AMS, the change management API provides operations to create and manage RFCs.
AWS SDK for Python (Boto3) – SDK for Python makes it easy to integrate your Python application, library, or script with AWS services.
Code
The AMS Stop EC2 Instance.zip
file (attached) contains the Python code for creating a Stop EC2 instance
RFC. You can also configure this code to submit a single RFC for multiple EC2 instances.
Epics
Task | Description | Skills required |
---|---|---|
Install and validate Python. |
| AWS systems administrator |
Install AWS CLI. | Run the | AWS systems administrator |
Install Boto3. | Run the | AWS systems administrator |
Install JSON. | Run the | AWS systems administrator |
Set up AMS CLI. | Sign in to the AWS Management Console, open the AMS console, and then choose Documentation. Download the .zip file that contains the AMS CLI, unzip it, and then install it on your local machine. After you install AMS CLI, run the | AWS systems administrator |
Task | Description | Skills required |
---|---|---|
Install and validate Python. |
| AWS systems administrator |
Install AWS CLI. | Run the | AWS systems administrator |
Install Boto3. | Run the | AWS systems administrator |
Install JSON. | Run the | AWS systems administrator |
Set up AMS CLI. | Sign in to the AWS Management Console, open the AMS console, and then choose Documentation. Download the .zip file that contains the AMS CLI, unzip it, and then install it on your local machine. After you install AMS CLI, run the | AWS systems administrator |
Task | Description | Skills required |
---|---|---|
Extract the CT ID, version, and execution parameters for the RFC. | Each RFC has a different CT ID, version, and execution parameters. You can extract this information by using one of the following options:
NoteTo adapt this pattern’s Python automation for other RFCs, replace the CT type and parameter values in the | AWS systems administrator |
Task | Description | Skills required |
---|---|---|
Run the Python automation. |
| AWS systems administrator |
Related resources
Attachments
To access additional content that is associated with this document, unzip the following file: attachment.zip