Skip to content

Instantly share code, notes, and snippets.

View alsoamit's full-sized avatar
📣
active

Amit Kumar alsoamit

📣
active
View GitHub Profile
@alsoamit
alsoamit / XRDP-MultiUser-Installation
Created May 9, 2024 06:40 — forked from aatizghimire/XRDP-MultiUser-Installation
This is short tutorial to install XRDP on Ubuntu for multi-user Remote desktop connection.
--------------------------------------------
Xrdp Server (Remote Desktop) Installation:
--------------------------------------------
Tested in Ubuntu 22.04.03 LTS
1. Update Environment
$ sudo apt-get update
$ sudo apt-get upgrade
@alsoamit
alsoamit / index.mjs
Last active July 24, 2024 06:53
Cognito saveUserDetailsPostConfirmation appsync integration lambda
// UPDATED for Node 20.x + and aws-sdk v3
import { DynamoDBClient, PutItemCommand } from "@aws-sdk/client-dynamodb";
const REGION = process.env.REGION;
const USERTABLE = process.env.USERTABLE;
const ddbClient = new DynamoDBClient({ region: REGION });
export const handler = async (event, context) => {
@alsoamit
alsoamit / .env.example
Last active March 13, 2024 08:53 — forked from oieduardorabelo/.env.example
Sample of Cognito with Server-Sider Authentication
PORT=xxx
COGNITO_USER_POOL_ID=xxx
COGNITO_CLIENT_ID=xxx
COOKIE_SESSION_SECRET=xxx
COOKIE_SESSION_NAME=xxx
AWS_REGION=xxx
AWS_ACCESS_KEY_ID=xxx
AWS_SECRET_ACCESS_KEY=xxx
@alsoamit
alsoamit / FAQItem.tsx
Created February 26, 2024 13:42
Microdata enabled FAQs
import React, { useState } from "react";
import { HiChevronDown } from "react-icons/hi";
export default function FAQItem({ item, isOpen }: any) {
const [open, setOpen] = useState(isOpen);
return (
<div
itemScope
itemProp="mainEntity"
@alsoamit
alsoamit / index.js
Last active September 7, 2023 07:49
Generate presigned url s3 nodejs 16.x (aws lambda & express js controller)
## This code example is optimized for Node 16.x runtime.
## Don't forget to add AWS_REGION and BUCKET_NAME as env variables in Lambda Configuration.
## Give the Lambda required permission to edit the Bucket.
const AWS = require('aws-sdk');
AWS.config.update({ region: process.env.AWS_REGION });
const s3 = new AWS.S3({
signatureVersion: "v4",
});
@alsoamit
alsoamit / readme.md
Created March 13, 2023 08:01
Linux User Management Commands

Create user (useradd)

sudo useradd <username>

This command adds an entry to these files:

  1. /etc/passwd
  2. /etc/group
  3. /etc/shadow
  4. /etc/gshadow
@alsoamit
alsoamit / Post.author.req.vtl
Last active March 13, 2023 08:00
Populate nested fields in aws appsync vtl resolvers
## Problem: How to populate all authors in a post in Appsync using Vtl resovlers?!
## Post(Parent Query) Structure:
## {
## id: ID!
## authorID: ID!
## author: User
## title: String!
## }
@alsoamit
alsoamit / Mutation.createTodo.req.vtl
Last active March 14, 2023 06:19
Auto-generate IDs and timestamps in AppSync Vtl Resolvers
{
"version": "2017-02-28",
"operation": "PutItem",
"key": {
"id": $util.dynamodb.toDynamoDBJson($util.autoId()),
},
#set($vals = $util.dynamodb.toMapValues($ctx.args.input))
#set($vals.createdAt = $util.dynamodb.toDynamoDB($util.time.nowISO8601()))
#set($vals.updatedAt = $util.dynamodb.toDynamoDB($util.time.nowISO8601()))
@alsoamit
alsoamit / index.mjs
Created March 13, 2023 07:29
Delete livestream using Mux SDK in aws Lambda Nodejs 18.x runtime
// Don't forget to include node_modules with "@mux/mux-node" installed in the Lambda
// Mux reads two environment variables MUX_TOKEN_ID and MUX_TOKEN_SECRET by default. Set them in the Lambda configuration.
import Mux from "@mux/mux-node";
const { Video, Data } = new Mux();
export const handler = async (event) => {
// Send id in the request body
// req.body = {id: <id-of-livestream-to-delete>}
const deletedLivestream = await Video.LiveStreams.del(event.id);
@alsoamit
alsoamit / index.mjs
Created March 13, 2023 07:25
List livestreams using Mux SDK in aws Lambda Nodejs 18.x runtime
// Don't forget to include node_modules with "@mux/mux-node" installed in the Lambda
// Mux reads two environment variables MUX_TOKEN_ID and MUX_TOKEN_SECRET by default. Set them in the Lambda configuration.
import Mux from "@mux/mux-node";
const { Video, Data } = new Mux();
export const handler = async (event) => {
const livestreams = await Video.LiveStreams.list();
const response = {