Skip to content

Instantly share code, notes, and snippets.

@alanzhaonys
alanzhaonys / bash_aws_jq_cheatsheet.sh
Created November 9, 2022 21:08 — forked from lukeplausin/bash_aws_jq_cheatsheet.sh
AWS, JQ and bash command cheat sheet. How to query, cut and munge things in JSON generally.
# Count total EBS based storage in AWS
aws ec2 describe-volumes | jq "[.Volumes[].Size] | add"
# Count total EBS storage with a tag filter
aws ec2 describe-volumes --filters "Name=tag:Name,Values=CloudEndure Volume qjenc" | jq "[.Volumes[].Size] | add"
# Describe instances concisely
aws ec2 describe-instances | jq '[.Reservations | .[] | .Instances | .[] | {InstanceId: .InstanceId, State: .State, SubnetId: .SubnetId, VpcId: .VpcId, Name: (.Tags[]|select(.Key=="Name")|.Value)}]'
# Wait until $instance_id is running and then immediately stop it again
aws ec2 wait instance-running --instance-id $instance_id && aws ec2 stop-instances --instance-id $instance_id
# Get 10th instance in the account
@alanzhaonys
alanzhaonys / sso.tf
Last active July 2, 2023 16:24
SSO User Creation Terraform
########## Data Soure ##########
data "aws_ssoadmin_instances" "my_dev_application" {}
data "aws_caller_identity" "current" {}
########## Locals ##########
locals {
account_id = data.aws_caller_identity.current.account_id
sso_user_email = "my.dev.application@gmail.com"
@alanzhaonys
alanzhaonys / updateUserFields.ts
Last active July 5, 2023 13:52
Reusable DynamoDb Function to Update Multiple Fields at Once
import { DateTime } from "luxon";
import {
AttributeValue,
DynamoDBClient,
QueryCommand,
UpdateItemCommand,
} from "@aws-sdk/client-dynamodb";
const dynamoDBClient = new DynamoDBClient({});
interface UserFields {
@alanzhaonys
alanzhaonys / apigateway-cognito-jwt-authorizer.yaml
Created July 10, 2023 02:57
Secure API Gateway with Cognito
AWSTemplateFormatVersion: "2010-09-09"
Parameters:
AppName:
Type: String
Default: apigateway-cognito-jwt-authorizer
Description: The application name
VpcCidrBlock:
Type: String