Skip to content

Instantly share code, notes, and snippets.

@ejdoh1
ejdoh1 / lambda_function.py
Created February 14, 2019 04:41
AWS Lambda function to call API Gateway with IAM auth
# Note: Allow Lambda action "execute-api:*" on your AWS API Gateway resources
import os
import requests
from requests_aws4auth import AWS4Auth
REGION = 'ap-southeast-2'
METHOD = 'POST'
SERVICE = 'execute-api'
@ejdoh1
ejdoh1 / run.py
Created April 17, 2019 15:17
AWS Pinpoint update_apns_sandbox_channel
# First export your APNS P12 cert from the Keychain Access app on your mac
# Keychain Access > Certificates > Select cert > right-click > Export as .p12 (passwd optional)
# Extract the cert and key from the p12 to use in the pinpoint calls
# openssl pkcs12 -in Certificates.p12 -out filename.key -nodes -nocerts
# openssl pkcs12 -in Certificates.p12 -clcerts -nokeys -out filename.crt
import boto3
APP_ID = "replace with Pinpoint App ID"
@ejdoh1
ejdoh1 / run.sh
Created April 18, 2019 00:52
Git set script as executable Windows
git update-index --chmod=+x 'script.sh'
@ejdoh1
ejdoh1 / notes.sh
Created May 2, 2019 01:17
Using you own CA with AWS IoT (web console method)
#From https://docs.aws.amazon.com/iot/latest/developerguide/device-certs-your-own.html
## Create a CA
openssl genrsa -out rootCA.key 2048
openssl req -x509 -new -nodes -key rootCA.key -sha256 -days 1024 -out rootCA.pem
## Register you CA with AWS IoT
### Get your registration code from: AWS Web Console > AWS IoT Core > Secure > CAs > Register > Register CA
@ejdoh1
ejdoh1 / settings.json
Created May 3, 2019 01:29
Golang autoformat not working in VSCode
{
"go.formatTool": "gofmt",
// the fix is to remove useLanguageServer setting
// "go.useLanguageServer": true,
}
@ejdoh1
ejdoh1 / chatscripts-gprs
Last active October 21, 2021 14:38
Raspberry Pi Zero with Simcom SIM7000E reporting to AWS IoT
# /etc/chatscripts/gprs
# You can use this script unmodified to connect to cellular networks.
# The APN is specified in the peers file as the argument of the -T command
# line option of chat(8).
# For details about the AT commands involved please consult the relevant
# standard: 3GPP TS 27.007 - AT command set for User Equipment (UE).
# (http://www.3gpp.org/ftp/Specs/html-info/27007.htm)
ABORT BUSY
@ejdoh1
ejdoh1 / install.sh
Created May 24, 2019 01:25
Install Go Lang 1.12.5 on Raspberry Pi 3 B+
cd $HOME
FileName='go1.12.5.linux-armv6l.tar.gz'
wget https://dl.google.com/go/$FileName
sudo tar -C /usr/local -xvf $FileName
cat >> ~/.bashrc << 'EOF'
export GOPATH=$HOME/go
export PATH=/usr/local/go/bin:$PATH:$GOPATH/bin
EOF
source ~/.bashrc
@ejdoh1
ejdoh1 / basic.py
Last active August 7, 2019 02:08
Boto3 AWS-RunPowerShellScript Example
import boto3
import time
INSTANCE_ID = "REPLACE_WITH_EC2_INSTANCE_ID"
SSM_RC_DOC_NAME = "AWS-RunPowerShellScript"
CMD_STATUS_SUCCESS = "Success"
CMD_WAIT_TIME = 2
CMD = "ipconfig"
@ejdoh1
ejdoh1 / lambda.py
Created August 7, 2019 02:21
Serverless Call IAM Authenticated AWS API Gateway
from botocore.vendored import requests
from requests_aws4auth import AWS4Auth
import os
URL = "https://myurl.com"
REGION = 'ap-southeast-2'
METHOD = 'GET'
SERVICE = 'execute-api'
def handler(event, context):
@ejdoh1
ejdoh1 / delete_user_and_profile_ssm_rc.py
Last active August 7, 2019 03:32
AWS SSM Powershell Run Command To Delete User and Profile
import boto3
import time
INSTANCE_ID = "REPLACE_ME"
USERNAME = "REPLACE_ME"
SSM_RC_DOC_NAME = "AWS-RunPowerShellScript"
CMD_STATUS_SUCCESS = "Success"
CMD_WAIT_TIME = 2