Giter Site home page Giter Site logo

0xsonu / aws_backend Goto Github PK

View Code? Open in Web Editor NEW
22.0 2.0 0.0 160 KB

AWS Lambda Appsync Cognito S3 Route53 Infrastructure Setup For Backend API

TypeScript 100.00%
amazon-web-services aws aws-sdk aws-serverless-backend backend-template cognito graphql javascript jest mongodb

aws_backend's Introduction

GraphQL API with AWS AppSync and MongoDB Template

An example serverless app created with SST.

Getting Started

Read the tutorial

Install the example.

git clone https://github.com/SonuKumar81800/AWS_Backend.git
cd AWS_Backend
npm install || yarn install

Install and Configure AWS cli

  • Download AWS Cli too from AWS Official
  • Install it in your local system.
  • Once your local environment is ready, head over to the AppSync console and get your access key id and secret here.

Open Terminal and follow these steps.

aws configure
AWS Access Key ID: <your_access_key_id>
AWS Secret Access Key:  <your_access_key_secret>
Default region name:  <select_your_region>
Default output format: json

Start the Live Lambda Development environment.

$ npm sst start

These Key Value you need to add to .env file

MONGO_USERNAME=<env_value>
MONGO_PASSWORD=<env_value>
DATABASE_NAME=<env_value>
DATABASE=<env_value>
GRAPHQL_API_URL=<env_value>
GRAPHQL_API_KEY=<env_value>

Commands

npm run start

Starts the local Lambda development environment.

npm run build

Build your app and synthesize your stacks.

Generates a .build/ directory with the compiled files and a .build/cdk.out/ directory with the synthesized CloudFormation stacks.

npm run deploy [stack]

Deploy all your stacks to AWS. Or optionally deploy a specific stack.

npm run remove [stack]

Remove all your stacks and all of their resources from AWS. Or optionally remove a specific stack.

npm run test

Runs your tests using Jest. Takes all the Jest CLI options.

Documentation

Learn more about SST.

Community

Follow us on Twitter or post on our forums.

aws_backend's People

Contributors

0xsonu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

aws_backend's Issues

Getting Error while adding string[] type to schema

Getting this error becouse of multiple graphql source in Stack Configuration.

Is there any way i can use seperate graphql schema for each section so that it will be easy to manage large applicatios.

Project Link

AWS_Backend Project

Error

 TypeError: mergeTypeDefs is not a function
    at AppSyncApi.createGraphApi (file:///E:/aws_projects/backend/node_modules/@serverless-stack/resources/dist/AppSyncApi.js:240:42)
    at new AppSyncApi (file:///E:/aws_projects/backend/node_modules/@serverless-stack/resources/dist/AppSyncApi.js:48:14)
    at EmptyStack.MyStack (file:///E:/aws_projects/backend/.build/lib/index.js:3386:15)
    at stack (file:///E:/aws_projects/backend/node_modules/@serverless-stack/resources/dist/FunctionalStack.js:15:35)
    at App.stack (file:///E:/aws_projects/backend/node_modules/@serverless-stack/resources/dist/App.js:336:16)
    at Module.main (file:///E:/aws_projects/backend/.build/lib/index.js:3437:7)
    at file:///E:/aws_projects/backend/.build/run.mjs:99:22 

folder structure

.
├── lib
│   ├── MyStack
│   ├── Resolvers
│   ├── Schemas
│   └── DataSources
├── src
│   ├── feature1
│   |  ├── feature1.graphql
│   |  ├── feature1.handler
│   |  ├── feature1.resolver
│   ├── feature2
│   |  ├── feature2.graphql
│   |  ├── ...
│   ├── ...
│   └── ...
└── ...

this is my stack configuration

import { StackContext, AppSyncApi, Cognito } from '@serverless-stack/resources';
import dataSources from './dataSources';
import resolvers from './resolvers';
import { AuthorizationType, UserPoolDefaultAction } from '@aws-cdk/aws-appsync-alpha';
import { Duration, Expiration } from 'aws-cdk-lib';

export function MyStack({ stack }: StackContext) {
  // Create the AppSync GraphQL API
  // mongodb+srv://doju:[email protected]/
  const auth = new Cognito(stack, 'Auth');

  const api = new AppSyncApi(stack, 'AppSyncApi', {
    schema: ['src/feature1/feature1.graphql','src/feature1/feature1.graphql'],
    defaults: {
      function: {
        timeout: 20,
        environment: {
          DATABASE:
            process.env.DATABASE ||
            `mongodb+srv://${process.env.MONGO_USERNAME}:${process.env.MONGO_PASSWORD}@atlascluster.sr2q4hg.mongodb.net/${process.env.DATABASE_NAME}?retryWrites=true&w=majority`,
          GRAPHQL_API_URL: process.env.GRAPHQL_API_URL || '',
          GRAPHQL_API_KEY: process.env.GRAPHQL_API_KEY || '',
        },
      },
    },
    cdk: {
      graphqlApi: {
        authorizationConfig: {
          defaultAuthorization: {
            authorizationType: AuthorizationType.USER_POOL,
            userPoolConfig: {
              userPool: auth.cdk.userPool,
              defaultAction: UserPoolDefaultAction.ALLOW,
            },
          },
          additionalAuthorizationModes: [
            {
              authorizationType: AuthorizationType.API_KEY,
              apiKeyConfig: {
                expires: Expiration.after(Duration.days(365)),
              },
            },
          ],
        },
      },
    },
    dataSources: dataSources,
    resolvers: { ...resolvers },
  });
  api.attachPermissions(['s3']);

  // Show the AppSync API Id in the output
  stack.addOutputs({
    ApiId: api.apiId,
    APiUrl: api.url,
    UserPoolId: auth.userPoolId,
    UserPoolClientId: auth.userPoolClientId,
  });
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.