Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
I may be slow to respond.

Dhaval Nagar dhavaln

💭
I may be slow to respond.
View GitHub Profile
@dhavaln
dhavaln / index.js
Last active Aug 17, 2021
Generate AWS Credentials using STS to limit S3 access
View index.js
const AWS = require('aws-sdk')
const STS = new AWS.STS();
const bucketName = 'appgambittest' //bucket where the data files are stored
const userId = 'user123' //userId who is requesting temporary access
const appId = 'userdir-user123' //directory name where the user data is available on s3
const roleArn = 'arn:aws:iam::XXXXXXXXXX:role/CustomS3AccessRole' //role with trust relationship and full bucket access
//generate inline session policy, with restricted access to the specific directory only
const generateInlinePolicy = (bucketName, folderName) => {
@dhavaln
dhavaln / .env
Last active Aug 13, 2021
MongoDB Atlas Serverless with NodeJS 4.1 Drivers
View .env
MONGO_URL=mongodb+srv://<USER>:<PASSWORD>@<LB>.mongodb.net/?retryWrites=true&w=majority
DB=
COLLECTION=
@dhavaln
dhavaln / id-pool-client.yml
Created Dec 30, 2020
Cognito Identity Pool Client Config
View id-pool-client.yml
Type: AWS::Cognito::UserPoolClient
Properties:
UserPoolId: !Ref cognitoUserPool
AllowedOAuthFlows:
- 'implicit'
AllowedOAuthFlowsUserPoolClient: true
AllowedOAuthScopes:
- 'openid'
- 'aws.cognito.signin.user.admin'
CallbackURLs:
@dhavaln
dhavaln / app-config.js
Created Dec 29, 2020
ServerlessDocs Frontend App Config
View app-config.js
//this file is in git ignore
//you need to create app-config.js, exact similar to this sample file, you can go to cloudformation stack output section to get all values
const userPoolId = '';
const normalClientId = '';
const region = 'us-west-2';
const identityPoolId = '';
const S3FilesBucket = '';
//=============== Cognito Group Name ===================
const adminGroupName = 'Admin'
//===============AWS Cognito Hosted Ui References==================
@dhavaln
dhavaln / identity-pool-client.yml
Last active Dec 29, 2020
Cognito Identity Pool client for Cognito User Pool Auth
View identity-pool-client.yml
Type: AWS::Cognito::UserPoolClient
Properties:
UserPoolId: !Ref cognitoUserPool
AllowedOAuthFlows:
- 'implicit'
AllowedOAuthFlowsUserPoolClient: true
AllowedOAuthScopes:
- 'openid'
- 'aws.cognito.signin.user.admin'
CallbackURLs:
@dhavaln
dhavaln / user-pool.yml
Created Dec 29, 2020
Amazon Cognito User Pool with Pre and Post triggers
View user-pool.yml
Type: AWS::Cognito::UserPool
Properties:
AccountRecoverySetting:
RecoveryMechanisms:
- Name: 'verified_email'
Priority: 2
AutoVerifiedAttributes:
- email
Policies:
PasswordPolicy:
@dhavaln
dhavaln / check-whitelist-domain.js
Created Dec 29, 2020
Check for Domains and Emails before Cognito Signup
View check-whitelist-domain.js
const whitelistedDomains = process.env.WHITE_LISTED_DOMAINS.split(',');
const whitelistedEmails = process.env.WHITE_LISTED_EMAIL.split(',');
exports.handler = async (event, context, callback) => {
console.log('Validate signup request', event);
console.log('wd', whitelistedDomains)
console.log('we', whitelistedEmails)
// Split the email address so we can compare domains
const userEmail = event.request.userAttributes.email;
@dhavaln
dhavaln / s3-folder-access.yml
Last active Dec 29, 2020
S3 Access Auth Role
View s3-folder-access.yml
- PolicyName: !Join ["-", [ "CognitoIDP", { Ref: AWS::StackName }, "S3-Access", "Policy"]]
PolicyDocument:
Version: "2012-10-17"
Statement:
- Sid: "AllowListingPublicFiles"
Effect: Allow
Action: "s3:ListBucket"
Condition:
StringLike:
"s3:prefix":
@dhavaln
dhavaln / README.md
Created Oct 16, 2019
Docker for Mac Volumes
View README.md

Only for Docker for Mac

Screen into the Docker Desktop

screen /Users/dhavalnagar/Library/Containers/com.docker.docker/Data/vms/0/tty

List the Volumes Directory

ls /var/lib/docker/volumes/

@dhavaln
dhavaln / Dockerfile
Created Oct 13, 2019
Simple NodeJS Multistage Build
View Dockerfile
FROM node:10 as build
MAINTAINER dhavaln
LABEL description="This is a multi-stage NodeJS image"
WORKDIR /src
COPY package*.json .
RUN npm install
COPY . .
FROM node:10-slim
WORKDIR /src