How Do You List the ELBs in Your AWS Account when You Know One Exists But the Command You Run Shows None?

Problem scenario
You run an AWS CLI command to list load balancers. It returns none. You know there are load balancers. What should you do?

Solution
Run these commands:

aws elb describe-load-balancers
aws elbv2 describe-load-balancers

(It could be that you have a newer load balancer or an older style load balancer. If you run both of the above commands,

How Do You Troubleshoot the Boto3 Error “AttributeError: ‘ec2.ServiceResource’ object has no attribute ‘terminate_instances'”?

Problem scenario
You are trying to terminate some EC-2 instances. But you see a message like this:

“AttributeError: ‘ec2.ServiceResource’ object has no attribute ‘terminate_instances'”
“AttributeError: ‘ec2.ServiceResource’ object has no attribute ‘destroy_instances'”
“AttributeError: ‘ec2.ServiceResource’ object has no attribute ‘delete_instances'”

What should you do?

Solution
Rewrite the terminate portion to look like this:

ec2.instances.filter(InstanceIds=[’i-0abcd1234′, ‘i-0wxyz9999’]).terminate() …

How Do You Use Boto and CloudFormation to Delete a Stack?

Problem scenario
You want to delete a CloudFormation Stack with Boto. What do you do?

Solution
Run a program like this (but replace “continualstack” with the name of the stack you deployed):

import boto3
cloudf = boto3.client(‘cloudformation’, region_name=’us-west-1′, aws_access_key_id=’AKIAMNOPQRST’, aws_secret_access_key=’FOOBAR1234/ZYXWV987654′)
json_stack=open(‘lampstack.json’, ‘r’).read()
cloudf.delete_stack(StackName=’continualstack’) …

How Do You Pass Two or More Subnets to an “aws eks” Command?

Problem scenario
You want to pass more than one subnet to an “aws eks” command.

You tried to delimit the list with commas (or separate two subnet IDs with commas). You received this error message:

An error occurred (InvalidParameterException) when calling the CreateNodegroup operation: The subnet ID ‘subnet-0abcd1234,subnet-zyxw9876’ does not exist (Service: AmazonEC2; Status Code: 400; Error Code: InvalidSubnetID.NotFound; Request ID: Proxy: null)

What should you do?

How Do You Deploy a Windows 2019 Server in AWS?

Problem scenario
You want to create a Windows 2016 server in AWS.  How do you do this?

Solution
1.  In the AWS Console go to the EC2 Dashbaord.
2.  Go to Launch Instance -Find the AMI for Microsoft Windows Server 2016 Base and click “Select.”
3.  Click “Next: Configure Instance Details”
4.  Click “Next: Add Storage”
5.  Click “Next: Add Tags”
6. 

How Do You Troubleshoot the Error “An error occurred (InvalidParameterException) when calling the CreateNodegroup operation: The provided nodeRole is invalid.”?

Problem scenario
From the AWS CLI you try to create a node group. But you get this error: “An error occurred (InvalidParameterException) when calling the CreateNodegroup operation: The provided nodeRole is invalid.”

Solution
The above can happen when you use a role’s name but not the ARN string (such as arn:aws:iam::123456:role/foobar). Use the ARN string of the role instead of what you were using.

How Do You Use Boto3 to Create EC-2 Instances?

Problem scenario
You want to create EC-2 instances using an SDK (a program that automatically generates AWS resources). How do you do this?

Solution
Prerequisites

You have Boto3 installed. If you need assistance, see this posting if you have CentOS/RHEL/Fedora or this posting for Debian/Ubuntu.

Procedures
Run this program to create a RHEL server (but you can replace the “ami-0a54aef4ef3b5f881” with the image ID of your choice):

# Replace AKIAabcdefghijk with your AWS access key ID
# Replace 1a2b3c4d5e6f7g8h9/i0j0k9l8m7n6o5p4q3r2s1tuvwxyz with your AWS Secret Access key
# Replace us-west-1 with the region of your choice
# Replace ami-0a54aef4ef3b5f881 with the image ID of your choice. …

How Do You Find out which VPC Your Lambda Function Is In?

Problem scenario
Some external requests that a Lambda function is making are not working. The Lambda logs indicate that the function is timing out. You want to see what VPC your Lambda function is in. What do you do?

Solution
Log into AWS via the web UI.
Go here (but change “us-west-1” in both places to your VPC’s region: https://us-west-1.console.aws.amazon.com/lambda/home?region=us-west-1#/functions/ )
Search for “VPC”
It may be that your Lambda function is not attached to any VPC.