Skip to content

Instantly share code, notes, and snippets.

View diegofcornejo's full-sized avatar
🪄
randomtechguy

Diego Cornejo diegofcornejo

🪄
randomtechguy
View GitHub Profile
@diegofcornejo
diegofcornejo / create-blog-hexo-cloudflare-ssl-.md
Last active January 22, 2019 04:43
How to create a blog using Hexo, Github Pages, Cloudflare with SSL - Step by step
@diegofcornejo
diegofcornejo / aws_ses_lambda.js
Last active January 22, 2019 04:45
Send email with AWS SES in Lambda
"use strict";
const AWS = require('aws-sdk');
const SES = new AWS.SES({ apiVersion: '2010-12-01' });
module.exports = {
send: function() {
var params = {
Destination: {
ToAddresses: [
"diegof.cornejo@gmail.com"
]
@diegofcornejo
diegofcornejo / nodemailer_lambda.js
Last active January 22, 2019 04:35
Send email with nodemailer in lambda
'use strict';
var nodemailer = require('nodemailer');
var aws = require('aws-sdk');
// create Nodemailer SES transporter
var transporter = nodemailer.createTransport({
SES: new aws.SES({
apiVersion: '2010-12-01'
})
@diegofcornejo
diegofcornejo / lambda_rds_ses.js
Last active July 12, 2020 21:55
Send an email with csv attachment created from query results
const aws = require('aws-sdk');
const nodemailer = require('nodemailer');
const mysql = require('mysql');
const json2csv = require('json2csv').parse;
const fs = require('fs');
// create Nodemailer SES transporter
var transporter = nodemailer.createTransport({
SES: new aws.SES({
apiVersion: '2010-12-01'
@diegofcornejo
diegofcornejo / lambda_sns_ses.js
Last active February 20, 2019 03:33
Lambda Process SNS pubs generated from SES events
const AWS = require('aws-sdk');
const EVENTS = new AWS.DynamoDB({ region: 'us-east-1', apiVersion: '2012-10-08' });
exports.handler = (event, context, callback) => {
var done = function(response) {
callback(null, response);
};
var message = JSON.parse(event.Records[0].Sns.Message);
var params = {
TableName: "ses-events",
Item: {
@diegofcornejo
diegofcornejo / createredirect.sh
Created February 20, 2019 03:32
Create a basic redirect system using lambda, s3 and cloudfront
#!/bin/sh
# Use -d subdomain.example.com -u https://randomtechguy.com
while getopts d:u: option
do
case "${option}"
in
d) DOMAIN=${OPTARG};;
u) URL=${OPTARG};;
esac
done
@diegofcornejo
diegofcornejo / node_dynamodb_xlsx.js
Created February 20, 2019 03:46
Create XLSX based on DynamoDB scan
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
const json2xls = require('json2xls');
var fs = require('fs');
var AWS = require('aws-sdk');
AWS.config.update({
region: "us-east-1",
});
@diegofcornejo
diegofcornejo / install_node_aarch64.sh
Last active October 6, 2021 23:59
Install Node JS & forever on AWS EC2 aarch64 - A1 & T4G Instances
#!/bin/bash
VERSION=6.17.1
curl -O https://nodejs.org/dist/v$VERSION/node-v$VERSION-linux-arm64.tar.xz
tar -xvf node-v$VERSION-linux-arm64.tar.xz
cd node-v$VERSION-linux-arm64
sudo cp -R * /usr/local/
sudo ln -s /usr/local/bin/node /usr/bin/node
sudo ln -s /usr/local/lib/node /usr/lib/node
sudo ln -s /usr/local/bin/npm /usr/bin/npm
npm install -g forever
@diegofcornejo
diegofcornejo / docker_certbot_manual.sh
Last active February 14, 2022 21:40
Generate Letsencrypt cert using Docker certbot image in manual mode
# Pull docker certbot image
docker pull certbot/certbot
# Create a dir for mount in containers, and save letsencrypt folders
mkdir letsencrypt # or any name you want
# Run a container and follow the instructions
docker run -it --rm -v "$PWD"/letsencrypt:/etc/letsencrypt certbot/certbot certonly --manual -d yourdomain.com
@diegofcornejo
diegofcornejo / invalidate_cloudfront_distributions.sh
Last active May 7, 2019 04:18
Invalidate Multiple AWS Cloudfront Distributions
#!/bin/bash
distributions=( EVJDT**** E3UI4***** E*****0X1FHL E26R******* ******RIN9KGU)
for i in "${distributions[@]}"
do
aws cloudfront create-invalidation --distribution-id $i --paths "/*" --profile yourProfile
done
#Remember add permision for execute and use "./invalidate_distributions.sh" not "sh invalidate_distributions.sh" because sh doesn't support array