Skip to content

Instantly share code, notes, and snippets.

Avatar
🥚
Probably eating

Nader Dabit dabit3

🥚
Probably eating
View GitHub Profile
@dabit3
dabit3 / storage.js
Created Feb 17, 2021
Example uploading / downloading files with S3, Amplify, & React
View storage.js
import { useState, useEffect } from 'react'
import { Storage } from 'aws-amplify'
function App() {
const [images, setImages] = useState([])
useEffect(() => {
fetchImages()
}, [])
async function fetchImages() {
let imageKeys = await Storage.list('')
@dabit3
dabit3 / add-user-trigger.js
Last active Feb 16, 2021
Add a user to DynamoDB after signing up
View add-user-trigger.js
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'},
@dabit3
dabit3 / main.ts
Created Feb 5, 2021
Checking for claims in the identity object - AppSync with Lambda
View main.ts
// To man manually check for groups, you can get the user's identity from
// the event.identity object, and check for claims in
// the event.identity.claims['cognito:groups']
function checkForGroup(event:AppSyncEvent, groupName:string) {
if (event.identity) {
if (event.identity.claims['cognito:groups']) {
if (event.identity.claims['cognito:groups'].includes(groupName)) {
return true
}
@dabit3
dabit3 / chime-methods.js
Last active Feb 4, 2021
Dealing with Chime SDK for creating rooms & attendees
View chime-methods.js
/* On the server */
const AWS = require('aws-sdk')
const chime = new AWS.Chime({ region: 'us-east-1' })
// create a room
const meeting = await chime.createMeeting({
ClientRequestToken: uuid(),
MediaRegion: 'us-east-1'
}).promise()
@dabit3
dabit3 / serverless.yml
Created Jan 22, 2021
Deploying Next.js to AWS with a custom domain name
View serverless.yml
nextamplified:
component: "@sls-next/serverless-component@1.18.0"
inputs:
domain: "nextjsonaws.com"
@dabit3
dabit3 / Dockerfile
Last active Jan 12, 2021
Next.js + Fargate Dockerfile
View Dockerfile
# Build locally
# docker build . -t nextapp
# Run locally
# docker run -it -p 8080:3000 nextapp
FROM public.ecr.aws/bitnami/node:14.15.1-debian-10-r8
WORKDIR /app
COPY package.json yarn.lock ./
RUN yarn
@dabit3
dabit3 / index.js
Last active Feb 2, 2021
Accessing Cognito Identity information on the server with Amplify, API Gateway, and Lambda
View index.js
// In a regular Lambda function
const user = event.requestContext.authorizer.claims
// In a Serverless Express route
const user = req.apiGateway.event.requestContext.authorizer.claims
// On client
async function callApi() {
const user = await Auth.currentAuthenticatedUser()
const token = user.signInUserSession.idToken.jwtToken
@dabit3
dabit3 / main.yml
Last active Dec 15, 2020
GitHub action for Next.js Serverless Component
View main.yml
# .github/workflows/main.yml
name: CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:
jobs:
build:
@dabit3
dabit3 / mytheme.itermcolors
Created Dec 3, 2020
Nader Dabit's iTerm2 theme
View mytheme.itermcolors
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Ansi 0 Color</key>
<dict>
<key>Alpha Component</key>
<real>1</real>
<key>Blue Component</key>
<real>0.0</real>
@dabit3
dabit3 / combined-config.js
Created Oct 29, 2020
Combining CDK outputs with Amplify configuration
View combined-config.js
import Amplify from 'aws-amplify';
const { AppsyncCdkAppStack } = require('./outputs.json');
import config from './aws-exports';
Amplify.configure({
...config,
aws_appsync_graphqlEndpoint: AppsyncCdkAppStack.GraphQLAPIURL,
aws_appsync_apiKey: AppsyncCdkAppStack.GraphQLAPIKey
})