Skip to content

Instantly share code, notes, and snippets.

View weisisheng's full-sized avatar

Vince Fulco--Bighire.tools weisisheng

View GitHub Profile
@weisisheng
weisisheng / add-user-trigger.js
Created October 4, 2021 06:32 — forked from dabit3/add-user-trigger.js
Add a user to DynamoDB after signing up
var aws = require('aws-sdk')
var ddb = new aws.DynamoDB()
exports.handler = async (event, context) => {
let date = new Date()
if (event.request.userAttributes.sub) {
let params = {
Item: {
'id': {S: event.request.userAttributes.sub},
'__typename': {S: 'User'},

How we incorporate next and cloudfront (2018-04-21)

Feel free to contact me at robert.balicki@gmail.com or tweet at me @statisticsftw

This is a rough outline of how we utilize next.js and S3/Cloudfront. Hope it helps!

It assumes some knowledge of AWS.

Goals

@weisisheng
weisisheng / openai-search-job-classification.py
Created August 1, 2021 12:24 — forked from ikanez/openai-search-job-classification.py
Prompt for GPT-3 for search capability
# based on job classification on jobstreet.com
job_classification = [
"accounting/finance",
"admin/human resources",
"sales/marketing",
"arts/media/communications",
"services",
"hotel/restaurant",
"education/training",
"computer/IT",
@weisisheng
weisisheng / README.md
Created July 27, 2021 05:52 — forked from julienma/README.md
GitHub Actions: using SSH keys to auto-deploy with dokku-push

The dokku-push action requires an SSH key with push access to the Dokku instance. Here's how to do that.

Replace APPNAME with the name of the app (e.g. this is a good idea to use the same name used on Dokku's).

Generate a new SSH keypair

We want each repo to have its own SSH key, so it's easier to rotate/invalidate them if required, without affecting all the repos. Let's generate a new key on your computer (see GitHub help):

@weisisheng
weisisheng / stripeWebhookLambdaHandler.js
Created July 14, 2021 13:51 — forked from thomasstep/stripeWebhookLambdaHandler.js
Stripe webhook handler code for AWS API Gateway and Lambda proxy integration
const stripe = require('stripe')(process.env.STRIPE_SECRET_KEY);
const {
updateUserSubscription,
deleteUserSubscription,
} = require('./database');
exports.handler = async function (event, context, callback) {
const webhookSecret = process.env.STRIPE_WEBHOOK_SECRET;
try {
const requestId = event?.requestContext?.requestId;
@weisisheng
weisisheng / directUploadToS3.js
Created July 10, 2021 06:08 — forked from DWboutin/directUploadToS3.js
Direct image url to S3 wiht axios and nodejs
import AWS from 'aws-sdk';
import stream from 'stream'
import axios from 'axios';
export default async (url, filename, callback) => {
const s3 = new AWS.S3({ params: { Bucket: process.env.STATIC_MAPS_BUCKET }});
let contentType = 'application/octet-stream'
let promise = null
const uploadStream = () => {
@weisisheng
weisisheng / README.md
Created May 27, 2021 06:29 — forked from plindberg/README.md
How to set up an AWS Lambda function for returning S3 pre-signed URLs for uploading files.

README

Granted, this is little more than an obfuscated way of having a publicly writable S3 bucket, but if you don’t have a server which can pre-sign URLs for you, this might be an acceptable solution.

For this to work, you take the following steps:

  1. Create a Lambda func, along with a new IAM role, keeping the default code.
  2. Create an API in the API Gateway.
@weisisheng
weisisheng / AWS_S3_File_Upload.js
Created May 24, 2021 08:16 — forked from homam/AWS_S3_File_Upload.js
How to upload files to AWS S3 with NodeJS SDK
var AWS = require('aws-sdk'),
fs = require('fs');
// For dev purposes only
AWS.config.update({ accessKeyId: '...', secretAccessKey: '...' });
// Read in the file, convert it to base64, store to S3
fs.readFile('del.txt', function (err, data) {
if (err) { throw err; }
@weisisheng
weisisheng / batch-write.js
Created May 14, 2021 07:11 — forked from rodolfo42/batch-write.js
DynamoDB streams lambda trigger
const items = [{
"Username": "First",
"Timestamp": "2017-08-07T19:51:00.794Z",
"Message": "first item in batch"
},
{
"Username": "Second",
"Timestamp": "2017-08-07T19:51:00.794Z",
"Message": "second item in batch"
},

Lambda note

Quick Start With DynamoDB

A DynamoDB stream is an ordered flow of information about changes to items in an Amazon DynamoDB table. In this case, lambda function poll the stream of DynamoDB 4 times per seconds and be trigered by an event of DynamoDB stream.

Futher reading: