1 AWS Setup

Go to the RMD, PDF, or HTML version of this file. Go back to Python Code Examples Repository (bookdown site) or the pyfan Package (API).

1.1 Installation on Local Machine

First install anaconda, git, and associated programs.

  1. Putty
  2. access to .pem key
  3. conda aws environment below

1.2 Conda AWS Environment

Can Start and Stop instances from Conda Prompt after this.

conda deactivate
conda list env
conda env remove -n wk_aws
conda create -n wk_aws -y
conda activate wk_aws

# Install External Tools
conda install -c anaconda pip -y

# Command line interface
conda install -c conda-forge awscli -y
# Programmatically send JSON instructions with boto3
conda install -c anaconda boto3 -y

1.3 AWS Account set-up

  1. Sign-up for AWS web services account (can be the same as your Amazon shopping account)
  2. Register for AWS Educate to get student or faculty voucher.
  • The University of Houston is a part of AWS Educate, choose educator or student, should hear back within 24 hours with coupon code.
  • UH students can get $100, faculty can get $200.

1.5 Use AWSCLI to Start and Stop an Instance

  1. Install AWS CLI
  2. Create individual IAM users
  3. Follow instructions to Configure your awscli, and profit access key id and secrete access key when prompted.
    • do not copy and paste the Key ID and Access Key. They are example, type these in as answers given config prompt:
    # aws configure
    AWS Access Key ID [None]: XXXXIOSFODNN7EXAMPLE
    AWS Secret Access Key [None]: wXalrXXtnXXXX/X7XXXXX/bXxXfiCXXXXXXXXXXX
    Default region name [None]: us-west-1
    Default output format [None]: json
    • this creates under a folder like this: C:/Users/fan/.aws, inside the folder these info will be stored in a configuration file.
    # the credentials file
    [default]
    aws_access_key_id = XXXXIOSFODNN7EXAMPLE
    aws_secret_access_key = wXalrXXtnXXXXX7XXXXXbXxXfiCXXXXXXXXXXX
    • then when you use aws cli, you will automatically be authenticated
  4. Start an instance in console first (or directly in command line). Stop it. do not terminate. Now this instance will have a fixed instance ID. Its DNS IP address will change every time you restart it, but its instance ID is fixed. Instance ID is found easily in the EC2 Console.
    aws ec2 run-instances --image-id ami-xxxxxxxx --count 1 --instance-type t2.micro --key-name MyKeyPair --security-group-ids sg-xxxxxxxx --subnet-id subnet-xxxxxxxx
    aws ec2 start-instances --instance-ids i-XXXXXXXX
    aws ec2 start-instances --instance-ids i-040c856530b2619bc
    aws ec2 stop-instances --instance-ids i-XXXXXXXX
    aws ec2 stop-instances --instance-ids i-040c856530b2619bc

1.6 Set-up SSM on EC2 Instance

To execute commandlines etc remote on EC2, need to set up SSM: AWS Systems Manager Agent (SSM Agent)

SSM-agent is already installed in Amazon Linux.

Error Message regarding InvalidInstanceId. The following scenarios can result in this error message:

  • Instance id is invalid (in the comments you have verified it isn’t)
  • Instance is in a different region (in the comments you have verified it isn’t)
  • Instance is not currently in the Running state
  • Instance does not have the AWS SSM agent installed and running.

“You have to create and attach the policy AmazonSSMFullAccess to the machine (thats maybe more broad than you need) but that was why it wasn’t working for me… You do that by clicking on (when selected on the ec2 instance) Action > Instance Settings > Attach/Replace IAM Role then create a role for ec2 that has that permission then attach, should take like 5-10 mins to pop up in SYSTEMS MANAGER SHARED RESOURCES - Managed Instances as mark mentions. – Glen Thompson Sep 20 ’18 at 16:31”

# Start SSM Agent with
sudo systemctl start amazon-ssm-agent