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 / 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 / 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 / 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 / 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 / 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 / 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
@diegofcornejo
diegofcornejo / README.MD
Last active March 7, 2020 05:19
Lambda - SNS - Process SES granular events and save into Cloud Firestore
  1. Download this file FirebaseAdminLayer.zip
  2. Create a Lambda Layer with the downloaded AdminFirebase.zip
  3. Attach FirebaseAdminLayer to your Lambda Function
@diegofcornejo
diegofcornejo / README.MD
Last active March 7, 2020 21:46
Express - SNS - Process SES granular events and save into Cloud Firestore

This assume you already have a SNS subscription (HTTP endpoint) and configured SES events, if not please go to this link

  1. Replace content from serviceAccountKey.json with your own info.

  2. Install dependencies

npm install --save express firebase-admin
@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'