

# Automatically create an RFC in AMS using Python
Automatically create an RFC using Python

*Gnanasekaran Kailasam, Amazon Web Services*

## 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](https://docs.aws.amazon.com/managedservices/latest/accelerate-guide/what-is-ams-op-plans.html) 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](https://docs.aws.amazon.com/managedservices/latest/ctexguide/ex-rfc-use-examples.html) – AMS helps you to operate your AWS infrastructure more efficiently and securely.
+ [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html) – 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)](https://docs.aws.amazon.com/pythonsdk/) – 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


### Option 1 – Set up environment for macOS or Linux



| Task | Description | Skills required | 
| --- | --- | --- | 
|  Install and validate Python.  | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/automatically-create-an-rfc-in-ams-using-python.html) | AWS systems administrator | 
|  Install AWS CLI.  | Run the `pip install awscli --upgrade –user` command to install AWS CLI*. * | AWS systems administrator | 
|  Install Boto3. | Run the `pip install boto3` command to install Boto3. | AWS systems administrator | 
| Install JSON.  | Run the `pip install json` command to install JSON. | 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 amscm help` command. The output provides information about the AMS change management process. | AWS systems administrator | 

### Option 2 – Set up environment for Windows



| Task | Description | Skills required | 
| --- | --- | --- | 
|  Install and validate Python.  | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/automatically-create-an-rfc-in-ams-using-python.html) | AWS systems administrator | 
| Install AWS CLI.  | Run the `pip install awscli --upgrade –user` command to install AWS CLI. | AWS systems administrator | 
|  Install Boto3. | Run the `pip install boto3` command to install Boto3. | AWS systems administrator | 
| Install JSON.  | Run the `pip install json` command to install JSON. | 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 amscm help` command. The output provides information about the AMS change management process | AWS systems administrator | 

### Extract the CT ID and execution parameters for the RFC



| 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:[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/automatically-create-an-rfc-in-ams-using-python.html)To adapt this pattern’s Python automation for other RFCs, replace the CT type and parameter values in the `ams_stop_ec2_instance` Python code file from the `AMS Stop EC2 Instance.zip` file (attached) with those that you extracted. | AWS systems administrator | 

### Run the Python automation



| Task | Description | Skills required | 
| --- | --- | --- | 
| Run the Python automation. | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/automatically-create-an-rfc-in-ams-using-python.html) | AWS systems administrator | 

## Related resources

+ [What are change types?](https://docs.aws.amazon.com/managedservices/latest/ctexguide/understanding-cts.html)
+ [CLI tutorial: High availability two-tier stack (Linux/RHEL)](https://docs.aws.amazon.com/managedservices/latest/ctexguide/tut-create-ha-stack.html)

## Attachments


To access additional content that is associated with this document, unzip the following file: [attachment.zip](samples/p-attach/2b6c68fd-a27e-4c8b-934d-caec50c196ed/attachments/attachment.zip)