How to access and use AWS Amazon?
HOW TO ACCESS AND USE AWS AMAZON?
ACCOUNT CREATION
We will use the Amazon Web Services (AWS) cloud for some of the labs.
There will not be one account per student, but one account per group of 5 students.
To access your AWS console, please go to: https://cloudbachelorlecture.signin.aws.amazon.com/console
The user is Bachelor-GroupXX, where XX is your group number.
The password will be provided during class.
CREATING YOUR FIRST AWS INSTANCE
Please follow this tutorial.
SETTING UP A LOCAL DEV. ENVIRONMENT
The AWS python SDK (Boto3) uses the AWS command-line interface credentials to connect AWS. Therefore, you first need to install AWS CLI.
To install AWS CLI run the following command:
pip3 install awscli --upgrade --user
You can test the installation by running the following command :
aws --version
Finally, log in to AWS with the AWS CLI using the following command :
aws configure
and fill up your AWS Access Key ID & AWS Secret Access Key (You can leave Default region name & Default output format to None)
Finally, you can install boto3. The following link will guide you through this installation:
https://boto3.amazonaws.com/v1/documentation/api/latest/guide/quickstart.html#installation
RESOURCES AND CODE EXAMPLES
CREATION OF INSTANCE
`````e2 = boto3.resource('ec2')
instances = ec2.create_instances(
ImageId="ami-0dafa01c8100180f8",
MinCount=1,
MaxCount=1,
InstanceType="t2.micro",
KeyName="KeyPair1"
)
GET THE STATUS OF AN INSTANCE
ec2= boto3.client('ec2')
response = ec2.describe_instance_status()
for instance in response['InstanceStatuses']:
instance_id = instance['InstanceId']
system_status = instance['SystemStatus']
instance_status = instance['InstanceStatus']
DELETION OF AN INSTANCE
ec2.instances.filter(InstanceIds = ids).terminate()
PUSH TO S3 BUCKET
s3 = session.resource('s3')
s3.upload_file(
'FILE_NAME', 'BUCKET_NAME', 'OBJECT_NAME',
)
READ FROM S3 BUCKET
s3 = boto3.client('s3')
s3.download_file('BUCKET_NAME', 'OBJECT_NAME', 'FILE_NAME')
MORE INFORMATION
Boto3 documentation
https://boto3.amazonaws.com/v1/documentation/api/latest/index.html
Code examples
You will find basic code examples on the official AWS SDK GitHub
https://github.com/awsdocs/aws-doc-sdk-examples/tree/master/python/example_code/ec2/ec2_basics
If you have any questions, please contact francisco(dot)mendonca(at)hesge(dot)ch