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 / !calling-lambda-cross-account.md
Created October 15, 2022 05:27 — forked from helephant/!calling-lambda-cross-account.md
Calling a lambda in another AWS account by assuming a cross-account IAM role

Set up a cross-account IAM role in the destination account

  • Add a new IAM role
  • For type of trusted entity select "another AWS account"
  • Specify the accountId of the account that will be using the resource in the destination account. You can find your AWS Account ID, which is available on the support homepage when you are logged in.
  • Create a policy that allows lambda:InvokeFunction for your function and attach it to this new role.

Create a lambda in the calling account.

  • Set up a role for your lambda that is allowed to assumeRole
  • Use the AWS SDK to assume the new role in the destination account.
  • Pass the credentials to the lambda object when you create it
@weisisheng
weisisheng / app.py
Created April 15, 2022 12:12 — forked from yashprakash13/app.py
FastApi example
import uvicorn
from fastapi import FastAPI
from model import SentimentModel, SentimentQueryModel
app = FastAPI()
model = SentimentModel()
@app.post('/predict')
def predict(data: SentimentQueryModel):
data = data.dict()
@weisisheng
weisisheng / spacy_preprocessor.py
Created February 14, 2022 14:34 — forked from omri374/spacy_preprocessor.py
Text preprocessing using spaCy
import re
from typing import List
import spacy
from spacy.tokens import Doc
from tqdm import tqdm
class SpacyPreprocessor:
def __init__(
// credentials are stored in a .env file with the following contents:
//
// accessKeyId=
// secretAccessKey=
// region=
// tableName=
// See: https://github.com/motdotla/dotenv
require("dotenv").config();
@weisisheng
weisisheng / lambda_function.py
Created January 15, 2022 00:53 — forked from fermayo/lambda_function.py
Lambda function to trigger a one-off ECS Fargate task
# Adapted from https://lobster1234.github.io/2017/12/03/run-tasks-with-aws-fargate-and-lambda/
import boto3
import os
def lambda_handler(event,context):
client = boto3.client('ecs')
response = client.run_task(
cluster=os.getenv('CLUSTER'),
launchType=os.getenv('LAUNCH_TYPE', 'FARGATE'),
@weisisheng
weisisheng / spacy_lambda_layer.sh
Created January 8, 2022 13:59 — forked from haranjackson/spacy_lambda_layer.sh
Deploys Python Spacy library to an AWS Lambda layer. You can specify the region, library version, language, language model, and runtime.
REGION=eu-west-1
VER=2.1.8
LANG=en
MODEL=en_core_web_sm-2.1.0
RUNTIME=python3.7
MODEL_URL=https://github.com/explosion/spacy-models/releases/download/$MODEL/$MODEL.tar.gz
docker run -v $(pwd):/out -it lambci/lambda:build-$RUNTIME \
pip install spacy==$VER $MODEL_URL -t /out/build/spacy/python
@weisisheng
weisisheng / generate-keypairs.sh
Created December 22, 2021 13:12 — forked from beingadityak/generate-keypairs.sh
Generate CloudFront Signed URLs for your private content
#!/usr/bin/env bash
openssl genrsa -out private_key.pem 2048 # generate an RSA private key of 2048 bits
openssl rsa -pubout -in private_key.pem -out public_key.pem # Generate the public key from the private key
@weisisheng
weisisheng / step-functions.md
Created November 28, 2021 10:16 — forked from vidanov/step-functions.md
AWS Step functions. InputPath, OutputPath, ResultPath

AWS Step functions

InputPath, OutputPath, ResultPath

  • InputPath -> the part of the original JSON payload to take to the step
  • OutPutPath -> the part of the original JSON payload to return after the step is completed
  • ResultPath -> here you can define a node to store the output you create in the step.

Please note "output" node is visible in the step function logs and here in the doc, but you do not have it in the function input. It means { "output": "1.05" } will be just

@weisisheng
weisisheng / index.js
Created November 13, 2021 17:15 — forked from graste/index.js
S3 Select query from NodeJS
const
AWS = require('aws-sdk'),
{ Readable } = require('readable-stream');
const s3 = new AWS.S3({
region: 'ap-northeast-2'
});
s3SelectQuery = (query) => {
return new Promise((resolve, reject) => {
@weisisheng
weisisheng / README.md
Created November 3, 2021 15:31 — forked from vdelacou/README.md
Create Multi Tenant AWS Amplify For B2B

npm install -g @aws-amplify/cli

npm init private

amplify init

? Enter a name for the project tenant
? Enter a name for the environment develop
? Choose your default editor: Visual Studio Code