Step 1

Step 1 - Launch an EC2 Instance using aws:runInstances

The first thing we will do is create an Automation document that launches a new EC2 instance using the action aws:runInstances.

Create the Custom Automation document

  • Open the AWS Systems Manager console at https://console.aws.amazon.com/systems-manager/.

  • In the navigation pane, choose Documents.

  • Choose Create automation.

  • For Name, type a descriptive name for the document, such as LaunchEC2Instance.

  • In the Document description section, provide the markdown style description for the document. You can provide instructions for using the document, numbered steps, or any other type of information to describe the document. For this session, enter the following description:

## NYCLoft Launch an EC2 instance using aws:runInstances
The purpose of this document is to launch an EC2 instance using the Automation action ```aws:runInstances```.

For a list of available Automation actions, see [Systems Manager Automation Actions Reference](https://docs.aws.amazon.com/en_us/systems-manager/latest/userguide/automation-actions.html).
  • For Assume Role, (optionally) enter the ARN of the Automation service role to use. For example, if you used Quick Setup within the Systems Manager console, the ARN for the Automation service role is in the format arn:aws:iam::111122223333:role/AmazonSSMRoleForAutomationAssumeQuickSetup. Note: You must change the account number to your AWS account number.

  • For Outputs, enter ["launchEc2Instance.InstanceIds"]. This will output the instance ID of the instance launched by Automation.

  • Expand the Input parameters sections and do the following.

    • For Parameter name, enter imageId.
    • For Data type, choose String.
    • For Required, choose No.
    • For Default value, enter {{ ssm:/aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-gp2 }}.
    • For Description, enter the following. (Optional) The AMI ID to use for launching the instance. The default value uses the latest released Amazon Linux AMI ID.
  • In the Step 1 section, provide the following information.

    • For Step Name, enter launchEc2Instance.
    • For Action type, select the action type Launch an instance (aws:runInstances).
    • For Description, optionally enter a description for the automation step. You can use Markdown to format your text.
    • Expand the Inputs section and enter {{ imageId }} for Image ID. By providing {{ imageId }} as the parameter, we can modify the AMI ID during the initiation of an Automation workflow.
  • Expand the Additional Inputs section, provide the following information.

    • For Input name, choose InstanceType and enter a valid instance type, such as t2.micro.
    • Choose Add optional input, for Input name choose IamInstanceProfileName and enter the name of the IAM Instance Profile that grants access to Systems Manager. For example, the IAM Instance Profile name is AmazonSSMRoleForInstancesQuickSetup if you used Quick Setup within the Systems Manager console.
  • Choose Create automation to save the document.

Run the Custom Automation Document

  • On the subsequent screen, choose View details or select Owned by me tab and then open the newly created automation document.

  • Choose Execute automation.

  • At the top of the Execute automation document page, verify that Simple execution is selected.

  • Choose Execute.

After the automation workflow completes, you can expand the Outputs section or click on the Step ID to review more details about the first step. This will include the instance ID of the newly launched Amazon Linux 2 EC2 instance.