Amazon Elastic Compute Cloud (EC2) provides scalable computing capacity in the AWS cloud. Using EC2 eliminates the need to invest in hardware upfront, so you can develop and deploy applications faster.
Example Code (Python using Boto3):
import boto3
ec2 = boto3.resource('ec2')
# Create a new EC2 instance
instances = ec2.create_instances(
ImageId='ami-0abcdef1234567890', # Replace with a valid image ID
MinCount=1,
MaxCount=1,
InstanceType='t2.micro',
KeyName='my-key-pair' # Replace with your key pair name
)
for instance in instances:
print('New instance created:', instance.id)