Skip to content

Instantly share code, notes, and snippets.

View dabit3's full-sized avatar
🎡
probably nothing

Nader Dabit dabit3

🎡
probably nothing
View GitHub Profile
@dabit3
dabit3 / storage.js
Created February 17, 2021 19:31
Example uploading / downloading files with S3, Amplify, & React
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 November 7, 2022 10:17
Add a user to DynamoDB after signing up
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 February 5, 2021 20:16
Checking for claims in the identity object - AppSync with Lambda
// 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 February 4, 2021 13:35
Dealing with Chime SDK for creating rooms & attendees
/* 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 January 22, 2021 23:45
Deploying Next.js to AWS with a custom domain name
nextamplified:
component: "@sls-next/[email protected]"
inputs:
domain: "nextjsonaws.com"
@dabit3
dabit3 / Dockerfile
Last active June 1, 2022 14:48
Next.js + Fargate 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 March 8, 2023 08:53
Accessing Cognito Identity information on the server with Amplify, API Gateway, and Lambda
// 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 December 15, 2020 20:59
GitHub action for Next.js Serverless Component
# .github/workflows/main.yml
name: CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:
jobs:
build:
@dabit3
dabit3 / mytheme.itermcolors
Created December 3, 2020 15:43
Nader Dabit's iTerm2 theme
<?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 October 29, 2020 17:33
Combining CDK outputs with Amplify configuration
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
})