Skip to content

Instantly share code, notes, and snippets.

@michalstala
michalstala / sorting-aws-cli-describe-images-output.md
Created October 3, 2018 09:54
How to sort AWS CLI describe-images output using jd

As an example query AWS for a list of all NAT Instance AMIs:


aws ec2 describe-images --filter Name="owner-alias",Values="amazon" --filter Name="name",Values="amzn-ami-vpc-nat*" --region us-west-2 | jq '.Images | sort_by(.CreationDate)'

If only specific fields are required to print into output:

@michalstala
michalstala / retrieve-ec2-region-from-instance-metadata.md
Created October 2, 2018 09:44
How to retrieve EC2 region information from instance metadata

Query the instance metadata using curl and parse the output with jq tool

curl --silent http://169.254.169.254/latest/dynamic/instance-identity/document | jq -r .region

Example Output:

us-east-1
@michalstala
michalstala / local-and-remote-ssh-port-forwarding.md
Created September 30, 2018 21:39
Local and Remote SSH port forwarding

Local SSH Port Forwarding

To start local forwarding, use the below command which will forward connections from local port 9001 to localhost:3306 on example.com server.

ssh -N -L 9001:localhost:3306 username@example.com

To connect with the destination, use localhost:9001 on local machine.

@michalstala
michalstala / nginx-as-reverse-proxy.md
Last active September 30, 2018 20:47
Configure nginx as reverse proxy to containerized Docker applications

The best practice is to run one worker process per core - it is defined by worker_processes directive. To verify how many cores is your machine running execute the grep processor /proc/cpuinfo | wc -l command. The worker_connections however specify how many simultaneous connections can be opened by a worker process (default value for nginx is 512).

Each docker aplications are defined in upstream directives. The request with URI /app1/ will be proxied to docker-app1, however the request with URI /app2/ will be proxied to docker-app2.

worker_processes 1;

events { 

    worker_connections 1024; 
@michalstala
michalstala / enable-mfadelete.md
Last active September 28, 2018 06:28
Enable MFA Delete for AWS S3 Buckets using AWS CLI

List all existing S3 buckets

Using root access keys run the aws s3api list-buckets command to return list of S3 buckets

Example Output:

{
    "Owner": {
        "DisplayName": "<OwnerName>",