Digital-Asset-Developer-Resources / aws

AWS required enviroment
GNU General Public License v3.0
0 stars 2 forks source link

Stepping through AWS "Create Instance" tutorial #2

Open kenricnelson opened 4 years ago

kenricnelson commented 4 years ago

Reference is: "https://aws.amazon.com/getting-started/tutorials/launch-a-virtual-machine/" The opening paragraph of this document suggests that Amazon Lightsail is easier to use; however, as this is an alternative to AWS EC2, I'll by-pass this for now. Maybe worth clarifying whether this is a useful alternative; perhaps for less experienced users.

Step 3 of the tutorial is "Configure your Instance". A question that arises is whether the configuration used in this tutorial is what's needed for running the cryptocurrency nodes. If not than one approach to the documentation could be to use this webpage as a template but modify it for our use. Scrolling through the files, there is a python script "AWS EC2" which appears to be the code necessary to configure an instance; however, the documentation doesn't currently make this explicit. Perhaps on the AWS readme page there should be an additional bullet "create an instance" which links to this python code.

In order utilize the python script "AWS EC2" I downloaded the "AWS" code via "Download ZIP" to my local drive. I launched "AWS EC2" via a Jupyter notebook. I ran the first code segment, which is:

import boto3 import os session = boto3.Session(profile_name='blockchain-nodes') ec2 = session.resource('ec2')

This produced error, presumably because the credentials file was not found:

ProfileNotFound Traceback (most recent call last)

in 2 import os 3 ----> 4 session = boto3.Session(profile_name='blockchain-nodes') 5 ec2 = session.resource('ec2') Stepping back, I have reviewed the AWS/Python/readme.md file; however, this document there is an aspect of this which is unclear. The first section "Configuration files" explains that the credentials file needs to be replaced; however, this did not allow that session to execute. Fixed problem by changing profile_name from "blockchain-nodes" to "default". The AWS document "https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html" was helpful in understanding that the ~/.aws/config file can contain multiple profiles. My config file just has "default". Recommend either changing the code to "default" or providing instructions to set up a profile for "blockchain-nodes". The next code section "Helper functions to find existing subnets and security group IDs." ran without incident. The section "Set Variables" had an error on the statement "VPC_ID, SUBNET_ID = get_subnet_id(AVZONE,'public')". Here is the code, as I modified it and the error produced: `BLOCKCHAIN_ID = "Nelson_Algorand" KEY_NAME = "ec2-keypair.pem" KEY_DIRECTORY = "Macintosh_HD⁩/Users⁩/kenricnelson⁩/AWS" SECURITYGROUP_NAME = "default-sg" DATAVOLUME_NAME = "Nelson_Algorand Devnet Chain Data" DATAVOLUME_SIZE = 100 INSTANCE_NAME = 'Nelson_Algorand Devnet' Amazon_Ubuntu_AMI_18_04_LTS = 'ami-0d5d9d301c853a04a' Instance_Type = 't2.micro' #micro=1GB, small=2GB, medium=4GB, large=8GB https://us-east-2.console.aws.amazon.com/ec2/v2/home?region=us-east-2#LaunchInstanceWizard: IAM_ROLE = "default-role" AVZONE = session.region_name+'b' VPC_ID, SUBNET_ID = get_subnet_id(AVZONE,"public") SECURITY_GROUP_ID = get_security_group_id(session,VPC_ID,SECURITYGROUP_NAME)` --------------------------------------------------------------------------- TypeError Traceback (most recent call last) in 17 18 AVZONE = session.region_name+'b' ---> 19 VPC_ID, SUBNET_ID = get_subnet_id(AVZONE,'public') 20 SECURITY_GROUP_ID = get_security_group_id(session,VPC_ID,SECURITYGROUP_NAME) in get_subnet_id(AVZONE, subnet_type) 6 for subnet in vpc.subnets.filter(Filters=[{"Name": "availabilityZone", "Values": [az["ZoneName"]]}]): 7 #print(vpc.id, az["ZoneName"], subnet.id, subnet.tags[0]['Value']) ----> 8 if (az["ZoneName"] == AVZONE) & (subnet_type in subnet.tags[0]['Value']): 9 return vpc.id, subnet.id 10 TypeError: 'NoneType' object is not subscriptable
kenricnelson commented 4 years ago

From the AWS Boto 3 documentation regarding describe_security_groups(**kwargs) the syntax seems different from the EC2 Helper Function code. Here's is the suggested syntax:

response = client.describe_security_groups( Filters=[ { 'Name': 'string', 'Values': [ 'string', ] }, ], GroupIds=[ 'string', ], GroupNames=[ 'string', ], DryRun=True|False, NextToken='string', MaxResults=123 )

I tried making modifications to the EC2:Helper Function script; however, it's not clear how hte GroupIDs should be set. Using the variable instance_security_group_id from the AWS VPC Create security group script, but this did not work.