AWS AppSync 和 Apollo 的无服务器 GraphQL 示例
** Archived - This repository is archived and preserved for reference only. No updates, issues, or pull requests will be accepted. If you have questions, please reach out to our support team.**
Part 1: Running a scalable & reliable GraphQL endpoint with Serverless
Part 2: AppSync Backend: AWS Managed GraphQL Service
Part 3: AppSync Frontend: AWS Managed GraphQL Service
This starter kit is an opinionated set of tools combined to help you get started building a Serverless application with a GraphQL endpoint and deploy them to production in minutes.
This example uses the following technologies:
Frontend
Backend
Other Utilities and Integrations
You need to have Node 6 or higher installed.
npm install -g serverless
npm install -g yarn
npm install -g netlify-cli
Install Dependencies.
yarn install
Please note: AWS CLI is required to be installed on your system
AWS Appsync (Serverless Offline does not support Appsync at this point)
Lambda Backend (Serverless Offline Supported)
cd app-backend/rest-api
yarn start
Generate your Consumer Key and Secret Key for a Twitter App and update config
DynamoDB
cd app-backend/dynamodb
yarn start
RDS
cd app-backend/rds
yarn start
For Appsync Backend please select Appsync Client Integration:
cd app-client/appsync-client/
yarn start
For Lambda Backend please select Apollo Client Integration:
cd app-client/apollo-client/
yarn start
Also, please make sure GraphQL endpoint is configured correctly in config/security.env.local to run client on local.
http://localhost:4000/graphiql
http://localhost:4000/playground
rest-api and dynamodb backends route GET and POST to the same /graphql endpoint handler
http://localhost:4000/graphql
{
getUserInfo(handle: "Madalyn61") {
name
tweets {
items {
retweeted
retweet_count
favorited
tweet
}
}
topTweet {
retweeted
retweet_count
favorited
}
}
}
If you've followed me this far, DynamoDB will now be available and running on your local machine at http://localhost:8000/shell:
Configure your AWS keys. Here you can find a 2min walkthrough how to do retrieve the keys.
sls config credentials --provider aws --key <your_aws_access_key> --secret <your_aws_secret_key>
You need to make sure you have access to your deployed lambda functions.
Note Please make sure latest serverless package is installed npm install -g serverless@latest
To use aws appsync you will need to create cognito user pool to authenticate the API Reference
- AWS DynamoDB
cd app-backend/appsync/dynamodb
yarn deploy-prod
yarn deploy-appsync
- AWS ElasticSearch
cd app-backend/appsync/dynamo-elasticsearch-lambda
yarn deploy-prod
yarn deploy-appsync
- AWS Lambda
cd app-backend/appsync/lambda
yarn deploy-prod
yarn deploy-appsync
Lambda Backend (Serverless Offline Supported)
Twitter Rest API
cd app-backend/rest-api
yarn deploy-prod
DynamoDB
cd app-backend/dynamodb
yarn deploy-prod
RDS
Create RDS Instance. For example - PostGres Tutorial
Please make sure connectivity to production RDS instance works (For example: test via razersql)
Edit the config/security.env.prod file and replace the DATABASE_URL variable with your amazon rds endpoint (eg: postgres://${username}:{password}@${endpoint):5432/${dbName}).
Run the deployment command
cd app-backend/rds
yarn deploy-prod
Config: Get your /graphql POST endpoint as shown below and use it in config/security.env.prod NOTE Please remove all quotes and <> and place only your POST endpoint url otherwise you will get 405 method not allowed error on POST to your endpoint
Select Frontend (apollo-client or appsync-client)
Note:
AWS S3
First you will need to choose custom s3 bucket name for client. For ex: s3-firstname-serverless-graphql. Please note that bucket name must be unique across all aws buckets.
Now, in app-client/<client-name>/serverless.yml edit the custom.client.bucketName property and replace it the bucket name above.
Now, in app-client/<client-name>/package.json edit the homepage property with https://${yourBucketName}.s3-website-us-east-1.amazonaws.com. For ex: https://s3-bucketname-serverless-graphql.s3-website-us-east-1.amazonaws.com
Run the deployment command
cd app-client/<client-name>/
yarn deploy-s3
# Your deployment url will be printed on the console
Your deployment url will be : https://s3.amazonaws.com/[bucket-name]/index.html
Netlify
First you will need to create a new account. Please see https://www.netlify.com/docs/cli/ for details.
Remove homepage property in app-client/<client-name>/package.json. This property is not required while deploying to netlify but is required for aws s3 deployment.
The first time you use the cli tool, you’ll be asked to authenticate through the browser. After you authenticate netlify will store an access token in a global ~/.netlify/config
Run deployment command
cd app-client/<client-name>/
yarn deploy-netlify
Your deployment url will be printed on the console
…
…
As the Serverless GraphQL Apollo community grows, we'd like to keep track of who is using the platform. Please send a PR with your company name and @githubhandle if you may.
Currently officially using Serverless GraphQL Apollo :
暂无开放 Issues,或尚未同步最近议题。