Wednesday, 14 August 2013

Running a shell command on EC2 using boto?

Running a shell command on EC2 using boto?

I am trying to find a way to pass a shell command to a Linux EC2 instance.
Basically I have a script which creates an EBS Volume, brings up a
CloudFormation stack, and then attaches the new volume to an EC2 instance
within the stack.
What I want to do, is to format and mount that volume as part of this
script, but I seem to have hit a road block at that point.
My python is not awesome, but I have managed to get through most of this,
while learning a bunch at the same time. I considered using Paramiko,
however I need to tunnel through a couple of servers to get to the subnet
of the instances.
# Attach an EBS volume to the EC2 Server instance
def attach_ebs(stack_id, results_volume):
resources = cfn.list_stack_resources(stack_id)
for r in resources:
if r.resource_type == "AWS::EC2::Instance" and "Server" in
r.logical_resource_id:
ec2.attach_volume(results_volume, r.physical_resource_id,
"/dev/sdh")

No comments:

Post a Comment