Skip to content

2019

aws-cloudwatch-logs-cloudtrail-logs-filters-sample

AWS VPC flowlogs CloudWatch logs CloudTrail logs and filters examples

Official Documentations - https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/FilterAndPatternSyntax.html


Basic sample VPC-flow-logs

[version, account, eni, source, destination, srcport, destport="8000", protocol, packets, bytes, windowstart, windowend, action, flowlogstatus]


VPC flow logs example with combination of AND

[version, account, eni, source="185.2*", destination, (srcport!="80" && srcport!="443"), (destport!="80" && destport!="443"), protocol, packets, bytes, windowstart, windowend, action, flowlogstatus]


Basic Expressions Operators

= -- EQUAL

!= -- NOT EQUAL

< -- SMALL THAN

> -- GRATER THEN

<= -- SMALL OR EQUAL

>= -- GRATER OR EQUAL

&& -- AND

|| -- OR


Cloud Trail Logs Filter examples

  • filter by Failure Console Logins 'ConsoleLogin="Failure"'

{ $.eventSource = "signin.amazonaws.com" && $.responseElements.ConsoleLogin = "Failure" }

  • exclude know IP address

{ ($.sourceIPAddress != "52.123.123.5") && ($.sourceIPAddress != "33.123.123.*") && ($.sourceIPAddress != "*.amazonaws.com") }

  • AWS login without using MFA

{ $.eventSource="signin.amazonaws.com" && $.additionalEventData.MFAUsed="No" }


Happy learning

Antonio Feijao UK

raspberry-pi-camera-resolution

Linux command lsusb

lsusb | grep -i cam

Bus 001 Device 004: ID 046d:0825 Logitech, Inc. Webcam C270
  • Now, use the Bus and Device numbers with -v option for verbose and filter for "Width|Height" and grep command.
$ lsusb -s 001:002 -v | egrep "Width|Height"

    wWidth    640
    wHeight   480
    wWidth    1280
    wHeight   1024
...

lsusb with sort awk grep uniq

I also like to use command likes sort, awk, grep and uniq.

echo "Maximum --> Width <-- will come on top" && lsusb -s 001:004 -v | grep "Width"  | awk '{print $2 " " $1}' | sort | uniq | sort -nr


echo "Maximum --> Height <-- will come on top" && lsusb -s 001:004 -v | grep "Height"  | awk '{print $2 " " $1}' | sort | uniq | sort -nr

v4l2-ctl

  • or another elegant option if available to you is :

v4l2-ctl --list-formats-ext

some credits go to

https://askubuntu.com/questions/214977/how-can-i-find-out-the-supported-webcam-resolutions

raspberry-pi-swap-memory

Raspberry Pi increase the swap memory size

  • First edit the swap configuration file

Change the size for your preference, Default is 100, (100MB)

Change for example for 2048 (2GB)

sudo vim /etc/dphys-swapfile

  • Second, restart the service

sudo /etc/init.d/dphys-swapfile restart

  • Confirm

Default swap file location is ls -lh /var/swap

-rw------- 1 root root 2.0G Feb 29 20:20 /var/swap

  • HTOP - you can also confirm with htop to see memory, cpu and swap usage.

If you do not have htop installed, you can install it with apt-get install htop

python3-learning

Python 3 learning for the first time

I have a background in shell scripting, so when I had to automate something, bash scripting would do the job just fine!

I also want to learn Python because is widely use nowadays and easy to integrate in most AWS Services, specifically useful for events with Lambda in AWS within serverless architectures.

Took me a while to do something useful with Python 3. At first, seemed an easy language to learn, and I still think it is!

If you already started first steeps, you know you can easily do print a print ("Hello World"), and you probably learnt a difference on the print command. From Python 2 to Python 3, you now have to use the parentheses ( ... )...

Just the command print is not enough to make something useful.

I thought that there might be someone else out there struggling to get started in Python 3, so I decided to share my experience on "How I start learning Python 3 and doing something useful".

You can execute command directly from running the command python3

CommandLine $ > python3
Python 3.7.4 (default, Jul  9 2019, 18:13:23)
[Clang 10.0.1 (clang-1001.0.46.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> print ("Hello World for AntonioCloud.com")
Hello World for AntonioCloud.com
>>>
>>> exit()
CommandLine $ >
CommandLine $ >

Then, I installed ipython and practice from there, but I was still on the basics commands and wanted to learn more.


Learn Python 3 on-the-go offline and mobile phone

After trying the basics, I set myself to practice on commute or free time.

Started by downloading the mobile app SoloLearn and started to practices while I was on commute. Some time later I completed the course, and Hey! Actually the final certificate feels like a good and well deserved rewards for completing the corse.

Here is mine [Antonio SoloLearn Python Certificate].


Learning by doing and practice often

So, after that, it really boosted my Python 3 skill when i started the fun project Stranger Things Alphabet Wall Lights.

With a fun challenge and with some physical visual result I felt is a lot more engaging.

commandI set fun challenge, something simple that only requires for loops, while loops and


Feedback

Feel free to leave a feedback and share your experience.

(...)

raspberry-pi-stranger-things-alphabet-wall-lights

Stranger Things Alphabet Wall Lights with Raspberry Pi Python 3 and Neopixels

It all started with the launch of Stranger Things Season 3.

We, Kat Decided to invite a couple of friend for the first episode of ST Session 3 and why not create some scary wall that spells out some words?!

Why not, right?

Proof of Concept

What I used:

  • 1x Raspberry PI 3b+ with power supply
  • 1x Pack of 50 addressable RGB LEDs from Amazon - (LINKS)[LINKS]
  • 1x Power supply 5V for the Raspberry PI
  • 1x Power supply 5v for the LEDs
  • 1x breadboard with a couple electric cables

(...)

aws-cli-find-all-instances-in-all-regions

Lists all ec2 instances in all regions including account owner, instance id, instance type, statues and region.

for region in `aws ec2 describe-regions --output text | cut -f4`; do
    echo -e "\nInstances in: '$region':";
    aws ec2 describe-instances --query 'Reservations[*].Instances[*].[NetworkInterfaces[0].OwnerId, Placement.AvailabilityZone, VpcId, InstanceId, InstanceType, State.Name]' --output text --region ${region};
done;

aws-cli-iam-roles-and-tokes

AWS cli IAM roles and tokens

aws sts assume-role --role-arn arn:aws:iam::ACCOUNT-NUMBER:role/ROLE-NAME --role-session-name "RoleSession1" | \
sed 's/[," :]//g;s/AccessKeyId/export AWS_ACCESS_KEY_ID=/;s/SessionToken/export AWS_SECURITY_TOKEN=/;s/SecretAccessKey/export AWS_SECRET_ACCESS_KEY=/' | \
grep 'export' | \
tee credentials.properties

export AWS_ACCESS_KEY_ID=xxxxxxxxxxx
export AWS_SECURITY_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
export AWS_SECRET_ACCESS_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx