0

Please give me code snippet to create windows ec2 instance using boto3 within aws free tier limit.

import boto3

# Create an AWS session and EC2 client
aws_management_console = boto3.session.Session(profile_name='....')
ec2_console = aws_management_console.client(service_name='ec2')

def create_ec2_instance():
try:
print("Creating EC2 instance")
ec2_console.run_instances(
ImageId="....",
MinCount=1,
MaxCount=1,
InstanceType="t3.micro",
KeyName="...",

SecurityGroupIds=['...1'] # Specify your security group ID(s) as a list
)
except Exception as e:
print(e)

# Call the function to create the EC2 instance
create_ec2_instance()
Have i missed anything in this code?
It's running fine not creating any instance.

Comments
  • 6
    You forgot:

    from yourmom import sofat

    sofat.earthquake()
  • 2
  • 5
    You can *technically* run a t2.micro with windows server 24/7 under free tier...

    That is, if you want to make your experience miserable by trying to run windows on a burstable instance with only 1 GB of RAM.

    Also, stay under 30 GB of total *combined* storage on GP2. Anything over is not free.
  • 2
    @udgirkar sorry, thought you were one of the bots. I don't use aws.
Add Comment