Skip to content

Instantly share code, notes, and snippets.

@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
@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 / 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 / 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 / gist:aa749751885e1639c998dffaa5659355
Last active September 8, 2021 15:35
Create a new AWS Account
1. Gmail account
2. Create AWS account
3. Create nac.fpmstaging.com NS records on the subaccount
3. Add NS records to the main account under nac.fpmstaging.com
4. Create a SSL cert for nac.fpmstaging.com
5. Create an IAM role `lambda-execute-role-cloudfront-basic-auth`
AWSLambdaExecute permission
Role need to have TrustedPolicy below(under Trust Relationships tab)

Today I connected my USB host board (see "hardware" section below) to my Wemos 1D device. It receives data from an outdoor "weather station receiver" and prints in to serial console in Arduino IDE.

Hardware:

Arduino libraries:

@alanzhaonys
alanzhaonys / gist:d42d3925e947fc8f9cfc4cc9c8fd6a44
Last active January 8, 2021 20:53
MySQL remote access on Centos 8 and Httpd
1. Setup user
2. Add binding_address = 0.0.0.0 to my.cnf
3. Open up firewall below
# https://wiki.mikejung.biz/Firewalld
# Allow traffic to MySQL
yum install @mysql
systemctl enable mysqld
systemctl start mysqld
systemctl status mysqld
@alanzhaonys
alanzhaonys / gist:19c965a453554eccaa827ec431e9075b
Last active November 30, 2020 14:30
PHP and Salesforce Integration
<?php
$request = [
'ws_key' => 'SMNXAgMDEA6GyPnYmMheW86AMLfKvqFTDGZR3dsTdcp41o',
];
$sfmc_ws = new SFMCWebService($request, true);
/**
* SFMC web services.
@alanzhaonys
alanzhaonys / gist:b69cf996ae6cdbfbd386a745da2b3bd6
Last active October 30, 2020 21:14
WordPress Admin Bar, Dashboard, head and footer Clean Up
<?php
//
//
// Below is the code that cleans up dashboard and admin bar
//
//
//
// Remove admin bar from frontend
@alanzhaonys
alanzhaonys / gist:bed46b6cb70e6edb01e96daa976339fc
Last active July 22, 2020 14:40
WordPress Hardening via .htaccess
# Block the include-only files.
# https://wordpress.org/support/article/hardening-wordpress/#securing-wp-includes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^wp-admin/includes/ - [F,L]
RewriteRule !^wp-includes/ - [S=3]
RewriteRule ^wp-includes/[^/]+\.php$ - [F,L]
RewriteRule ^wp-includes/js/tinymce/langs/.+\.php - [F,L]
RewriteRule ^wp-includes/theme-compat/ - [F,L]