import boto3 from user_data import user_data from credentials import ( aws_access_key_id, aws_secret_access_key, aws_session_token, DEFAULT_VPC ) PREFIX = 'sassy' if __name__ == '__main__': ec2 = boto3.resource( 'ec2', region_name='us-east-1', aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key, aws_session_token=aws_session_token, ) key_pair = ec2.create_key_pair( KeyName=PREFIX + '-key', KeyType='ed25519', KeyFormat='pem', ) security_group = ec2.create_security_group( Description=PREFIX + '-group', GroupName=PREFIX + '-group', VpcId=DEFAULT_VPC, ) inbound_rules = security_group.authorize_ingress( GroupId=security_group.group_id, CidrIp='0.0.0.0/0', IpProtocol='tcp', FromPort=80, ToPort=80, ) instances = ec2.create_instances( ImageId='ami-0b5eea76982371e91', MinCount=1, MaxCount=1, InstanceType='t2.micro', KeyName=key_pair.name, UserData=user_data, SecurityGroups=[security_group.group_name], )