Skip to content

Instantly share code, notes, and snippets.

View agusrichard's full-sized avatar

Agus Richard Lubis agusrichard

View GitHub Profile
import amqp, { Message } from 'amqplib/callback_api'
const createMQConsumer = (amqpURl: string, queueName: string) => {
console.log('Connecting to RabbitMQ...')
return () => {
amqp.connect(amqpURl, (errConn, conn) => {
if (errConn) {
throw errConn
}
import amqp, { Connection } from 'amqplib/callback_api'
const createMQProducer = (amqpUrl: string, queueName: string) => {
console.log('Connecting to RabbitMQ...')
let ch: any
amqp.connect(amqpUrl, (errorConnect: Error, connection: Connection) => {
if (errorConnect) {
console.log('Error connecting to RabbitMQ: ', errorConnect)
return
}
import bodyParser from 'body-parser'
import express, { Request, Response } from 'express'
const PORT = 3001
const app = express()
app.use(bodyParser.json())
app.get('/', (req: Request, res: Response) => {
import bodyParser from 'body-parser'
import express, { Request, Response } from 'express'
const PORT = 3000
const app = express()
app.use(bodyParser.json())
app.post('/register', (req: Request, res: Response) => {
{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig.json to read more about this file */
/* Language and Environment */
"target": "es6", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
/* Modules */
"module": "commonjs", /* Specify what module code is generated. */
"rootDir": "./src", /* Specify the root folder within your source files. */
# Base image
FROM python:3.9
# Set environment varibles
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
WORKDIR /app
COPY requirements.txt /app/requirements.txt
from fastapi import FastAPI
app = FastAPI()
@app.get('/')
def index():
return 'Hello World!'
import os
import boto3
import pathlib
from dotenv import load_dotenv
from boto3.resources.base import ServiceResource
base_dir = pathlib.Path(__file__).parent.parent.parent
load_dotenv(base_dir.joinpath('.env'))
DB_REGION_NAME=<REGION_NAME>
DB_ACCESS_KEY_ID=<ACCESS_KEY_ID>
DB_SECRET_ACCESS_KEY=<SECRET_ACCESS_KEY>
import boto3
def generate_table(ddb):
ddb = boto3.resource('dynamodb',
endpoint_url='http://localhost:8000',
region_name='example', # note that if you create a table using different region name and aws key
aws_access_key_id='example', # you won't see this table on the admin app
aws_secret_access_key='example')
ddb.create_table(