Part 2 - Manage AWS infrastructure Easily with PromptOps: No IaC Needed

This is the second post in a series of posts where we will explore how PromptOps makes managing AWS infrastructure easy and faster. We will also explore some new features which we have added to improve the experience around authoring and remembering commonly used prompts. A Real Example: Setting Up a Docker Host on an AWS EC2 VM While part1 was focused on a lightsail vm, this post is focused on provisioning an EC2 VM and bootstrapping it as a docker host. Mandatory Parameters In order to provision an AWS EC2 VM, one need to pass two mandatory parameters as follows - AMI (Amazon Machine Image) / OS Instance type To get these values you can execute following prompt after selecting a region in MechCloud AWS Agent where you want to provision the vm - list images list instance types which are free tier eligible Please note that AWS API for listing AMIs does not provide any filter to list free tier eligible AMIs and so we have restricted list images to return AMIs having Name tag where the value of this tag must be one of the values in the Ubuntu 24.04, Amazon Linux 2023 list. Querying by Name tag is mandatory and so if you don't specify Name tag while querying the AMIs, it will be automated added while executing the prompt. Also before querying the AMIs, make sure you have updated Name tag for all the AMIs which you want to use for provisioning EC2 VMs. This is especially useful in those situations where free tier eligible AMIs can be easily identified using human readable names assigned to Name tag to take maximum advantage of free tier (while learning AWS). If you want to query different set of AMIs, you can use following prompt - list images with following tag(s) - Name|Ubuntu 22.04 You can specify any additional tag in addition to Name tag. Now you can use following prompt to provision an EC2 VM - provision an ec2 vm with following details - image - '' instance type - t2.micro t2.micro may not be available in all the AWS regions. So replace it with the one you will see in the output of list instance types which are free tier eligible prompt executed above. While you can take AMI id from the output of list images prompt, it is difficult to tell which OS an AMI id points to when looking at such prompts in the history of AWS agent. To simplify this we have introduced resource id aliases where an AWS resource can be referenced using a human readable identifier instead of its unique id generated by AWS in a prompt. Here is the simplified prompt for provisioning an EC2 VM using 'Ubuntu 24.04' AMI - provision an ec2 vm with following details - image - '@Image|Ubuntu 24.04' instance type - t2.micro However, this will only work if you have listed AMIs at least once for the selected region in the AWS agent and if Ubuntu AMI for 24.04 version has a Name tag with value as Ubuntu 24.04. You will need to execute prompt for all the associated resources (image in this case) after switching to a different region in the AWS agent as this will clear all the aliases which were created for the old AWS region. In general, if you list resources of a particular type (e.g. vpc, subnet etc) and in the result table you see a column which mentions a Prefix next to it then it means that the values in such column can be used as aliases at any place where you are required to use the id of the resource. An alias should be in @| format. Any underlined text in a table like above can be copied to clipboard just by clicking on it which makes copying values from such tables faster. While this is good for testing purpose, we can't ssh into the newly created vm because we didn't specify an ssh key while creating the vm. Also we need to open ssh port (22) before we can connect to this vm using its public ip. Now let's import our ssh public key and create a security group which we will attach to a VM while provisioning it. To import ssh public key, you can use following prompt - import an ec2 key pair with following details - name - testKey1 key - base64_encode() base64_encode() function is not supported in AWS agent prompts at this moment. The above prompt simply means that you should base64 encode your ssh key before passing it in the above prompt. This is also different from similar prompt for lightsail when base64 encoding of ssh public key is not required while importing a key pair. To create a security group one can use following prompt which will also open ssh port (22) for inbound traffic - create a security group with following details - name - securitygroup-ssh description - Allow access on ssh port ----- add following ingress rules - 22|tcp|@CURRENT_IP Initialize aliases for key pairs and security groups by executing following prompts - list ec2 key pairs list security groups Now you can provision an AWS VM using following prompt with the ssh key pair and security group created above - provision an ec2 vm with following detail

Mar 27, 2025 - 12:39
 0
Part 2 - Manage AWS infrastructure Easily with PromptOps: No IaC Needed

This is the second post in a series of posts where we will explore how PromptOps makes managing AWS infrastructure easy and faster. We will also explore some new features which we have added to improve the experience around authoring and remembering commonly used prompts.

A Real Example: Setting Up a Docker Host on an AWS EC2 VM

While part1 was focused on a lightsail vm, this post is focused on provisioning an EC2 VM and bootstrapping it as a docker host.

Mandatory Parameters

In order to provision an AWS EC2 VM, one need to pass two mandatory parameters as follows -

  • AMI (Amazon Machine Image) / OS
  • Instance type

To get these values you can execute following prompt after selecting a region in MechCloud AWS Agent where you want to provision the vm -

list images
list instance types which are free tier eligible

Image 1

Please note that AWS API for listing AMIs does not provide any filter to list free tier eligible AMIs and so we have restricted list images to return AMIs having Name tag where the value of this tag must be one of the values in the Ubuntu 24.04, Amazon Linux 2023 list. Querying by Name tag is mandatory and so if you don't specify Name tag while querying the AMIs, it will be automated added while executing the prompt. Also before querying the AMIs, make sure you have updated Name tag for all the AMIs which you want to use for provisioning EC2 VMs. This is especially useful in those situations where free tier eligible AMIs can be easily identified using human readable names assigned to Name tag to take maximum advantage of free tier (while learning AWS).

If you want to query different set of AMIs, you can use following prompt -

list images with following tag(s) -
Name|Ubuntu 22.04

You can specify any additional tag in addition to Name tag.

Now you can use following prompt to provision an EC2 VM -

provision an ec2 vm with following details -
image - ''
instance type - t2.micro

t2.micro may not be available in all the AWS regions. So replace it with the one you will see in the output of list instance types which are free tier eligible prompt executed above.

While you can take AMI id from the output of list images prompt, it is difficult to tell which OS an AMI id points to when looking at such prompts in the history of AWS agent. To simplify this we have introduced resource id aliases where an AWS resource can be referenced using a human readable identifier instead of its unique id generated by AWS in a prompt. Here is the simplified prompt for provisioning an EC2 VM using 'Ubuntu 24.04' AMI -

provision an ec2 vm with following details -
image - '@Image|Ubuntu 24.04'
instance type - t2.micro

However, this will only work if you have listed AMIs at least once for the selected region in the AWS agent and if Ubuntu AMI for 24.04 version has a Name tag with value as Ubuntu 24.04. You will need to execute prompt for all the associated resources (image in this case) after switching to a different region in the AWS agent as this will clear all the aliases which were created for the old AWS region.

In general, if you list resources of a particular type (e.g. vpc, subnet etc) and in the result table you see a column which mentions a Prefix next to it then it means that the values in such column can be used as aliases at any place where you are required to use the id of the resource. An alias should be in @| format.

Image 2

Any underlined text in a table like above can be copied to clipboard just by clicking on it which makes copying values from such tables faster.

While this is good for testing purpose, we can't ssh into the newly created vm because we didn't specify an ssh key while creating the vm. Also we need to open ssh port (22) before we can connect to this vm using its public ip.

Now let's import our ssh public key and create a security group which we will attach to a VM while provisioning it. To import ssh public key, you can use following prompt -

import an ec2 key pair with following details -
name - testKey1
key - base64_encode()

base64_encode() function is not supported in AWS agent prompts at this moment. The above prompt simply means that you should base64 encode your ssh key before passing it in the above prompt. This is also different from similar prompt for lightsail when base64 encoding of ssh public key is not required while importing a key pair.

To create a security group one can use following prompt which will also open ssh port (22) for inbound traffic -

create a security group with following details -
name - securitygroup-ssh
description - Allow access on ssh port
-----
  add following ingress rules -
  22|tcp|@CURRENT_IP

Initialize aliases for key pairs and security groups by executing following prompts -

list ec2 key pairs
list security groups

Now you can provision an AWS VM using following prompt with the ssh key pair and security group created above -

provision an ec2 vm with following details -
image - '@Image|Ubuntu 24.04'
instance type - t2.micro
key pair - testKey1
security group - '@SecurityGroup|securitygroup-ssh'
tags -
Name|vm2

We also specified Name tag in the above prompt so that newly created vm can be identified easily.

List the vms using list ec2 vms prompt and note down the public ip of newly created vm. Now you can connect to this vm using its public ip and the ssh private key associated with the ssh public key which you had used while importing a ssh key pair.

Finally, let's move to the next step and create a new vm which should have docker installed. To achieve this we will use the same script which we had used to bootstrap a lightsail vm as a docker host in part1 of this series. Here is the prompt for provisioning and bootstrapping a vm as docker host -

provision an ec2 vm with following details -
image - '@Image|Ubuntu 24.04'
instance type - t2.micro
key pair - testKey1
security group - '@SecurityGroup|securitygroup-ssh'
user data - base64_encode("#!/bin/bash\ncurl -fsSL https://raw.githubusercontent.com/mechcloud/sample-scripts/refs/heads/main/install-docker.sh | bash")
tags -
Name|vm3

Again, base64_encode() is still not supported in AWS agent prompt. It simply means that one need to base64 encode the value passed as argument to this function and then use it as the value of user data field. One more difference is that the script must start with a shebang line (#!/bin/bash) otherwise it will not work.