Published on

Useful commands

Authors
  • avatar
    Name
    Gene Zhang
    Twitter

Bash

Show port usage and kill process:

sudo lsof -i :8080
sudo kill -9 <PID>

AWS

Secret manager:

# Get secret value
aws secretsmanager get-secret-value \
--secret-id <secret-id> \
--region <region> \
--profile <profile-name>

# Get secret value and parse it
aws secretsmanager get-secret-value \
--secret-id <secret-id> \
--region <region> \
--query SecretString \
--output text \
--profile <profile-name>

# Get secret value and parse it with jq
aws secretsmanager get-secret-value \
--secret-id <secret-id> \
--region <region> \
--query SecretString \
--output text \
--profile <profile-name> \
| jq -r '.password'

# Create a new secret

aws secretsmanager create-secret \
--name <secret-name> \
--secret-string <secret-string> \
--profile <profile-name>

# Update a secret
aws secretsmanager put-secret-value \
 --secret-id <secret-id> \
 --secret-string <secret-string> \
 --profile <profile-name>
```

# API Gateway

Filter the request to a path: `/my/path` in CloudWatch Logs Insights

```bash
fields @timestamp, @message, @logStream
| filter @message like "/my/path"
| sort @timestamp desc
| limit 100
```

# Git

Cherry pick to current branch:

```bash
# Cherry-pick without committing (stages changes only)
git cherry-pick --no-commit <commit-hash>

# Cherry-pick and continue if there are conflicts
git cherry-pick --continue

# Abort cherry-pick if there are conflicts
git cherry-pick --abort

# Skip current commit in cherry-pick sequence
git cherry-pick --skip
```

# Kubernetes

```
 Bash(kubectl -n marketplace exec deployment/my-service -- wget -O- http://localhost:3001/ 2>&1 | head -20)
  ⎿  Connecting to localhost:3001 ([::1]:3001)
     Hello World!writing to stdout
```

## Context

```bash
# Get current context
kubectl config current-context

# List all contexts
kubectl config get-contexts

# Set context
kubectl config use-context <context-name>

# View context details
kubectl config view --minify

# Set namespace for current context
kubectl config set-context --current --namespace=<namespace>
```