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:

# Enable EPEL
yum -y install epel-release
yum install mosquitto
systemctl enable mosquitto
systemctl start mosquitto
# Generate password
mosquitto_passwd -c /etc/mosquitto/passwd sammy
@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:1f13a45415bb75e1a741f68da0dc4e72
Last active March 5, 2020 17:06
Centos 8 Own Cloud Installation
https://download.owncloud.org/download/repositories/production/owncloud/
CentOS_8 owncloud-files-10.4.0-1
Run the following shell commands as root to trust the repository.
rpm --import https://download.owncloud.org/download/repositories/production/CentOS_8/repodata/repomd.xml.key
Run the following shell commands as root to add the repository and install from there. You either need 'dnf upgrade' or 'dnf install' depending on whether you already have an older version installed or not.
dnf config-manager --add-repo http://download.owncloud.org/download/repositories/production/CentOS_8/ce:stable.repo
dnf clean all
@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