
Why Should You Learn AWS DevOps In 2025?
AWS DevOps combines the power of Amazon Web Services (AWS) with DevOps practices to streamline software development and deployment.
- AWS credentials (Access Key, Secret Key).
- IAM role with sufficient permissions (e.g.,
ec2:RunInstances
,ec2:DescribeInstances
). - Python installed along with
boto3
.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import boto3
# Initialize a session using Amazon EC2
ec2_client = boto3.client('ec2', region_name='us-east-1')
# Configuration for the EC2 instance
def launch_ec2_instance():
try:
# Launch the EC2 instance
response = ec2_client.run_instances(
ImageId='ami-0c02fb55956c7d316', # Amazon Linux 2 AMI ID
InstanceType='t2.micro',
KeyName='my-key-pair', # Replace with your key pair
MinCount=1,
MaxCount=1,
SecurityGroupIds=['sg-0abcd1234abcd5678'], # Replace with your SG ID
SubnetId='subnet-0abcd1234abcd5678', # Replace with your subnet ID
TagSpecifications=[
{
'ResourceType': 'instance',
'Tags': [
{'Key': 'Name', 'Value': 'MyAWSDevOpsInstance'}
]
}
]
)
# Print instance details
instance_id = response['Instances'][0]['InstanceId']
print(f"EC2 Instance launched successfully! Instance ID: {instance_id}")
return instance_id
except Exception as e:
print(f"Error launching EC2 instance: {str(e)}")
return None
# Call the function to deploy the instance
if __name__ == "__main__":
instance_id = launch_ec2_instance()