Skip to content

Instantly share code, notes, and snippets.

@philschmid
Last active October 21, 2019 13:48
Show Gist options
  • Save philschmid/d97a80ca02d27fef07a03e815edd16ef to your computer and use it in GitHub Desktop.
Save philschmid/d97a80ca02d27fef07a03e815edd16ef to your computer and use it in GitHub Desktop.
boto3 start ec2 instances
import boto3
client = boto3.client('ec2', region_name='us-west-2')
user_data= '''#!/bin/bash
echo 'test' > /tmp/hello'''
response = client.run_instances(
BlockDeviceMappings=[
{
'DeviceName': '/dev/xvda',
'Ebs': {
'DeleteOnTermination': True,
'VolumeSize': 8,
'VolumeType': 'gp2'
},
},
],
ImageId='ami-6cd6f714',
InstanceType='t3.micro',
MaxCount=1,
MinCount=1,
Monitoring={
'Enabled': False
},
SecurityGroupIds=[
'sg-1f39854x',
],
user_data=user_data,
)
@philschmid
Copy link
Author

philschmid commented Oct 21, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment