How Can You Use CloudTrail for the First Time in Your AWS Account?

Problem scenario
You want to log or monitor AWS activity (e.g., AWS Management Console, AWS CLI, and/or AWS SDK actions). You do not want encryption because you are just testing it out. How do you use CloudTrail to do this?

Solution

  1. Log into AWS.
  2. Go to this link: https://console.aws.amazon.com/cloudtrail/
  3. Click "Create a trail"
  4. Enter a descriptive name for your trail.
  5. Click "Create trail"
  6. Do some operations in AWS (e.g., create an EC-2 instance).
  7. Go here: https://console.aws.amazon.com/cloudtrail/
  8. Click on "Event history"
  9. Click the "30m" or "1h" to filter the events.

(We recommend using encryption for production uses. The above is just for a proof-of-concept.)

How Do You Fix the Stack Storm Error “Failed to authenticate”?

Problem scenario
You run an st2 command, but it fails with an error like this:

Failed to authenticate with credentials provided in the config.
ERROR: 401 Client Error: Unauthorized
MESSAGE: Invalid or missing credentials for url: http://127.0.0.1:9100/tokens

What should you do?

Solution
Run a command like this (but replace "jdoe" and "passwordhere" with your credentials respectively):

st2 login jdoe --password 'passwordhere'

Now run the st2 command(s).

How Do You Pass an Array to a Method in Java?

Problem scenario
You want to pass an argument to another piece of code (e.g., a function in Java). How do you pass an array as a parameter to another portion of code?

Solution
Java only has methods -- not functions (according to this posting).

This code (which should be called contInt.java) will pass a two-dimensional array called twoD to the method "coolp".

import java.util.*;
class contInt
{
 static String[][] boardprinter(String [][] arr1) {
   return arr1;
 }

 public static void main(String[] args) {
    String twoD[][] = new String[3][3];
    twoD[0][0] = "i";
    twoD[0][1] = "h";
    twoD[0][2] = "g";
    twoD[1][0] = "f";
    twoD[1][1] = "e";
    twoD[1][2] = "d";
    twoD[2][0] = "c";
    twoD[2][1] = "b";
    twoD[2][2] = "a";
    String [][] var1 =  boardprinter(twoD);
    System.out.println("The print function is below from the variable passed to another method.");
    coolp(twoD);

 }

 static void coolp(String[][] twoD) {
    String [][] var1 =  boardprinter(twoD);
    String composite1 = "|" + var1[0][0] + "|" + var1[0][1] + "|" + var1[0][2] + "|";
    System.out.println(composite1);
  }
}

How Do You Create Peering Connections to EC-2 Instances, inside VPCs, So They Can Communicate with Each Other?

Problem scenario
You want to use peering connections between two VPCs (in the same region) so that EC-2 instances in each VPC can communicate with each other. How do you do this?

Solution
Prerequisite

This assumes you have two VPCs already created in the same region. This assumes you have EC-2 instances also created.

i. Create one VPC. Go to VPC and give it a name. Create an IPv4 CIDR block (e.g., 55.55.0.0/24 or 66.66.0.0/16). We find it is easier if the VPC has "Edit DNS Hostnames" enabled; you can do this by going to the VPCs, clicking the radio button for the VPC, then going to Actions -> Edit DNS hostnames, and choose "enable", and clicking "Save."

ii. Create a second VPC as you did in step i.

iii. Create EC-2 instances in the VPCs above. When you create each one, make sure it is created in the VPC you want. Step 3 is "Configure Instance Details" (if you are using the web console). The "Network" drop down option should show the VPC you want. If you have to create a subnet, use one of the options in VPC CIDRs. We find it to be easier to choose the "Enable" drop down option for "Auto-assign Public IP".

iv. Ensure the NACLs that govern the subnets of your VPCs allow connectivity from your workstation. The inbound rules must have the IP address of your workstation even if there is a rule for 0.0.0.0 (allow all IP addresses). If you go to VPC -> Security -> Network ACLs, you can find one that governs a subnet. The website ipchicken.com can help you out with your public IP address (of your workstation). The format of the IP address in field will be like this: 123.123.123.123/32

v. Make sure the EC-2 instances have Security Groups with Inbound rules that permit connectivity from your workstation.

vi. Finally if you need to connect to these two EC-2 instances, you may want to create an Internet Gateway for each VPC. Then you will want to modify the Route table of the VPC to have traffic destined for 0.0.0.0/0 route to the internet gateway.

Procedures

  1. Create a Peering Connection. Go to VPC -> Virtual Private Cloud -> Peering Connections.
  2. Click "Create Peering Connection". Enter the necessary information.
  3. Click "Create Peering Connection".
  4. Click "Ok".
  5. Click the radio button near the Peering Connection. Go to Actions -> Accept Request.
  6. Click "Yes, Accept".
  7. Go to Virtual Private Cloud -> Route Tables.
  8. Expand the column for "VPC ID" to see the names of the VPCs.
  9. Click the radio button for one of the relevant VPCs.
  10. Click the "Routes" tab.
  11. Click "Edit Routes"
  12. In the "Destination" drop down text field, enter the internal IP address of the other EC-2 instance that is not in this VPC with a "/32" at the end (e.g., 55.55.123.123/32)
  13. For the "Target" drop down, choose "Peering Connection" and then click on the specific one that you just created.
  14. Click "Save routes".
  15. Click "Route Tables" near the upper right hand corner and repeat steps 8 through 14 for the other VPC that you have not done these steps for.
  16. Modify the respective Security Groups that govern each of the EC-2 instances to allow inbound connections from the internal IP addresses of each other.

In our experience modifications to Route Tables happen instantly; there is no delay.

How Do You Troubleshoot the Error “unexpected EOF while looking for match `\”‘”?

Problem scenario
You run a Bash command or an Ansible playbook, but you get stymied by this problem: "unexpected EOF while looking for match `\"'"

What should you do when you see this message?

Solution
Verify your escape characters have a space after the symbol that they are escaping.

For example, if you have \""

change it to \" "

The escape character may be working on two sequential symbols (without a space).

How Do You Troubleshoot “ModuleNotFoundError: No module named ‘zlib'”?

Problem scenario
You are trying to install Python 3 but you get a message about zlib. This is the full message:

rm /usr/local/lib/python3.9/lib-dynload/_sysconfigdata__linux_x86_64-linux-gnu.py
rm -r /usr/local/lib/python3.9/lib-dynload/__pycache__
/bin/install -c -m 644 ./Misc/python.man \
        /usr/local/share/man/man1/python3.9.1
if test "xupgrade" != "xno"  ; then \
        case upgrade in \
                upgrade) ensurepip="--altinstall --upgrade" ;; \
                install|*) ensurepip="--altinstall" ;; \
        esac; \
         ./python -E -m ensurepip \
                $ensurepip --root=/ ; \
fi
Traceback (most recent call last):
  File "<frozen zipimport>", line 520, in _get_decompress_func
ModuleNotFoundError: No module named 'zlib'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<frozen zipimport>", line 568, in _get_data
  File "<frozen zipimport>", line 523, in _get_decompress_func
zipimport.ZipImportError: can't decompress data; zlib not available

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/Python-3.9.0a1/Lib/runpy.py", line 193, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/bin/Python-3.9.0a1/Lib/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/usr/bin/Python-3.9.0a1/Lib/ensurepip/__main__.py", line 5, in <module>
    sys.exit(ensurepip._main())
  File "/usr/bin/Python-3.9.0a1/Lib/ensurepip/__init__.py", line 203, in _main
    return _bootstrap(
  File "/usr/bin/Python-3.9.0a1/Lib/ensurepip/__init__.py", line 122, in _bootstrap
    return _run_pip(args + [p[0] for p in _PROJECTS], additional_paths)
  File "/usr/bin/Python-3.9.0a1/Lib/ensurepip/__init__.py", line 30, in _run_pip
    import pip._internal
  File "<frozen zipimport>", line 241, in load_module
  File "<frozen zipimport>", line 709, in _get_module_code
  File "<frozen zipimport>", line 570, in _get_data
zipimport.ZipImportError: can't decompress data; zlib not available
make: *** [Makefile:1200: altinstall] Error 1

Solution
Run this:
sudo yum -y install zlib-devel

(If you get a "yum command not found" error, go to this site.)

How Do You Make a PDF Smaller?

Problem scenario
You want your PDF to retain the same content. But you want the file size to be reduced. You have access to a command prompt of an Ubuntu Linux server with no GUI environment. What should you do?

Possible Solution #1
If the fidelity of the reduced size PDF is important, try this solution (as we believe it is relatively lossless).

1. Install Ghostscript:

sudo apt -y install ghostscript

2. Run the following two commands where "foobar.pdf" is the name of your large PDF file:

pdf2ps foobar.pdf foobar.ps
ps2pdf foobar.ps smallfoobar.pdf

Possible Solution #2
If a minor reduction in quality is acceptable and it is very important to reduce the size by a large amount, try this solution.

  1. Install this package:
    sudo apt -y install graphicsmagick-imagemagick-compat
  2. Run this command (where foobar.pdf is the name of the PDF you want to shrink):
    convert foobar.pdf -compress Zip small.pdf

How Do You Troubleshoot “build.cfg No such file” or “libgnu.a No Such file”?

Problem scenario
You do not have make installed, but you are trying to install it. You get the following message:

build.sh: line 21: ./build.cfg: No such file or directory
sed: can't read lib/Makefile: No such file or directory
sed: can't read lib/Makefile: No such file or directory
sed: can't read Makefile: No such file or directory
sed: can't read lib/Makefile: No such file or directory
./lib/libgnu.a: No such file or directory

What should you do?

Solution
Run these commands:

cd /path/to/directory/with/make/files
sudo ./configure --prefix=/usr/local  #do not be alarmed if there are errors
sudo bash build.sh
# Some errors can be ignored.  You may be able to proceed even if you saw errors.

If you want to install make from scratch on any type of Linux, see this posting.