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. …

What Is The Difference between Iterable and Subscriptable in Python?

Question
You have seen messages when coding in Python about iterable and subscriptable. What is the difference between these two?

Answer
A subscriptable does not necessarily use the iter method, but an iterable always does.

A subscriptable object in Python leverages the getitem() method, but it may or may not use the iter method.

How Do You Troubleshoot an apt Command That Has an Error “An error occurred during the signature verification”?

Problem scenario
You are trying to run an apt command. It is failing. You get an error like this:

W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: http://repo.mongodb.org/apt/ubuntu…/foobar/1.1 Release: The following signatures were invalid: KEYEXPIRED 1507497109

What should you do?

Possible solution #1
This is not recommended.

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.

How Do You Troubleshoot dpkg Errors from apt Commands like “package post-installation script subprocess returned error exit status 1”?

Problem scenario
On a Debian/Ubuntu server, you are trying to run apt commands. But you get errors like this:

dpkg: error processing package oracle-java11-installer-local (–configure):
installed oracle-java11-installer-local package post-installation script subprocess returned error exit status 1
Setting up nmap-common (7.80+dfsg1-2build1) …
Setting up liblua5.3-0:amd64 (5.3.3-1.1ubuntu2) …
dpkg: dependency problems prevent configuration of default-jre-headless:
default-jre-headless depends on openjdk-11-jre-headless; however:
Package openjdk-11-jre-headless is not installed.

Using an Android phone, How Do You Turn on Notifications of Voicemail?

Problem scenario
You received voicemails, but there was no indication you received them. How do you get notified that you have a voicemail with an Android phone?

Solution
1. Find the Voicemail application.
2. Open it and go to Settings -Notifications
3. Make sure the “Show notifications” is turned on

How Do You Display a Fixed Number of Numbers after the Decimal Point in Python?

Problem scenario
You want to display a specific number of places after the decimal (e.g., one, two or three) with numeric values in Python. You want the decimal value to be rounded if it is too long. How do you always show (including trailing zeroes) a specific number of places to the right of the decimal point?

Solution
This Python 3 program will illustrate how:

x=123.45678
y=”{:.3f}”.format(x)
print(y)

a=123
b=”{:.1f}”.format(a)
print(b) …

How Do You Install snap on a RHEL 8.x Server?

Problem scenario
You want to use Juju (e.g., to install Kubernetes in AWS). You are using RHEL 8.x. What should you do?

Solution
Run these commands:

sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
sudo dnf upgrade
sudo yum install snapd
sudo systemctl enable –now snapd.socket
sudo ln -s /var/lib/snapd/snap /snap

Log out and log back in.