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 / cdk-chat-stack.ts
Last active August 21, 2021 12:42
Creating an AWS AppSync GraphQL API with CDK
const api = new GraphqlApi(this, 'cdk-chat-app-api', {
name: "cdk-chat-app",
logConfig: {
fieldLogLevel: FieldLogLevel.ALL,
},
schema: Schema.fromAsset('graphql/schema.graphql'),
authorizationConfig: {
defaultAuthorization: {
authorizationType: AuthorizationType.USER_POOL,
userPoolConfig: {
@dabit3
dabit3 / cdk-chat-stack.ts
Last active October 11, 2024 12:52
Creating DynamoDB tables with a GSI with CDK
const messageTable = new Table(this, 'CDKMessageTable', {
billingMode: BillingMode.PAY_PER_REQUEST,
partitionKey: {
name: 'id',
type: AttributeType.STRING,
},
});
const roomTable = new Table(this, 'CDKRoomTable', {
billingMode: BillingMode.PAY_PER_REQUEST,
@dabit3
dabit3 / cdk-chat-stack.ts
Last active August 19, 2020 13:24
Creating a Cognito User Pool for authentication with CDK
const userPool = new UserPool(this, 'chat-app-user-pool', {
selfSignUpEnabled: true,
accountRecovery: AccountRecovery.PHONE_AND_EMAIL,
userVerification: {
emailStyle: VerificationEmailStyle.CODE
},
autoVerify: {
email: true
},
standardAttributes: {
@dabit3
dabit3 / cdk-chat-stack.ts
Last active September 29, 2020 18:37
CDK Imports
import * as cdk from '@aws-cdk/core';
import { UserPool, VerificationEmailStyle, UserPoolClient, AccountRecovery } from '@aws-cdk/aws-cognito';
import { GraphqlApi, AuthorizationType, FieldLogLevel, MappingTemplate, Schema } from '@aws-cdk/aws-appsync';
import { AttributeType, BillingMode, Table } from '@aws-cdk/aws-dynamodb';
import { Role, ServicePrincipal, Effect, PolicyStatement } from '@aws-cdk/aws-iam';
@dabit3
dabit3 / cdk-chat-stack.ts
Last active December 20, 2022 06:38
CDK Chat App CDK
import * as cdk from '@aws-cdk/core';
import { UserPool, VerificationEmailStyle, UserPoolClient, AccountRecovery } from '@aws-cdk/aws-cognito';
import { GraphQLApi, AuthorizationType, FieldLogLevel, MappingTemplate, SchemaDefinition } from '@aws-cdk/aws-appsync';
import { AttributeType, BillingMode, Table } from '@aws-cdk/aws-dynamodb';
import { Role, ServicePrincipal, Effect, PolicyStatement } from '@aws-cdk/aws-iam';
export class CdkChatStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
@dabit3
dabit3 / schema.graphql
Last active August 19, 2020 12:58
AppSync Chat Schema
type Message {
id: ID!
content: String!
owner: String
createdAt: String
roomId: ID
}
type Room {
id: ID!
@dabit3
dabit3 / appsync-cdk-stack.ts
Last active December 30, 2021 16:17
Todo app AppSync API with CDK
import * as cdk from '@aws-cdk/core';
import { CfnApiKey, PrimaryKey, Values, GraphQLApi, MappingTemplate, FieldLogLevel, AttributeValues } from '@aws-cdk/aws-appsync'
import { AttributeType, BillingMode, Table } from '@aws-cdk/aws-dynamodb';
import * as lambda from '@aws-cdk/aws-lambda'
import { join } from 'path';
export class AppsyncCdkStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
@dabit3
dabit3 / reactstreaming.js
Last active November 10, 2022 04:46
React Streaming code from live broadcast
import React from 'react';
import logo from './logo.svg';
import './App.css';
import ReactPlayer from 'react-player'
import { HashRouter, Link, Switch, Route } from 'react-router-dom'
import AuthComponent from './AuthComponent'
import { Auth, API } from 'aws-amplify'
import { createComment as CreateComment } from './graphql/mutations'
import { listComments as ListComments } from './graphql/queries'
import { onCreateComment as OnCreateComment } from './graphql/subscriptions'
@dabit3
dabit3 / resizetrigger.js
Created July 20, 2020 23:07
Image Resize Lambda Trigger
const sharp = require("sharp");
const aws = require("aws-sdk");
const s3 = new aws.S3();
exports.handler = async function(event, context) {
if (event.Records[0].eventName === "ObjectRemoved:Delete") {
return;
}
const BUCKET = event.Records[0].s3.bucket.name;
const KEY = event.Records[0].s3.object.key;
@dabit3
dabit3 / schema.graphql
Last active July 4, 2020 14:52
Access patterns for getting user and associated orders
type Customer @model(subscriptions: null)
@auth(rules: [
{ allow: owner },
{ allow: groups, groups: ["Admin"] }
]) {
id: ID!
name: String!
email: String!
address: String
orders: [Order] @connection(keyName: "byCustomerId", fields: ["id"])