在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):nikhilaravi/serverless-graphql开源软件地址(OpenSource Url):https://github.com/nikhilaravi/serverless-graphql开源编程语言(OpenSource Language):JavaScript 75.2%开源软件介绍(OpenSource Introduction):Serverless-GraphQLA Serverless Jukebox app built using AWS Lambda, React, GraphQL, API Gateway and Node.js. You can search for songs using the Last.fm api and save the names of songs you like to a playlist. Technologies
ArchitectureThis repo has all the code for the GraphQL Lambda function and creation of an s3 bucket and API Gateway endpoint connected to the lambda function. In addition to the GraphQL Lambda there are three other lambda functions
The GraphQL IDE and UI live here: https://github.com/nikhilaravi/serverless-graphql-app Before you start
Add the following environment variables to a .env file AWS_ACCOUNT_ID=[your_account_id_here]
AWS_ACCESS_KEY_ID=[your_key_here]
AWS_SECRET_ACCESS_KEY=[your_secret_here]
AWS_REGION=[aws_region] (e.g. 'eu-west-1')
API_KEY=[lastfm_api_key] Start building!1. Create IAM RolesAWS requires you to specify the permissions which are given to different resources e.g. who can view the objects inside an s3 bucket, who can invoke a lambda function etc. These permissions are defined as policies and for different IAM roles which can then be assigned to different services or external services like CodeShip. npm run create-iam This will create an iam role for the lambda function and print it in the terminal. Export this as an environment variable. This role will be used by the deploy script. export AWS_IAM_ROLE="arn:account_id:role_name" 2. Create an s3 bucket to use as the data storeWhen a track is added to the playlist, it will be saved as a json file in s3. An s3 bucket needs to be created and given permission to be modified by other AWS services (i.e. permission to allow our Lambda to write and read from it). Modify the name of the bucket at the top of Create the bucket using the following command: npm run create-s3 and to the
3. Create the microservicesThere are three microservices apart from the GraphQL microservice. Clone the following repos and run
The lambda functions are zipped and uploaded to AWS using the
Have a look at the notes in the dpl npm module docs or ask @nelsonic for more info! Then save the following three environment variables to the LAMBDA_SONG_SUGGESTER=song-suggester-v1
LAMBDA_S3_SAVE=s3-save-v1
LAMBDA_S3_GET=s3-get-v1 4. Create a GraphQL lambda function and connect it to an API GATEWAY endpoint.Now time to deploy the GraphQL lambda function and connect it to the API endpoint! To modify the name of the API you can edit the npm run deploy-app The Have a look at the The last command is a test invocation of the api gateway endpoint to check it has been connected correctly with the lambda. It should print a list of songs which have the name 'Stronger'! 4. Enable CORS in the AWS Console and get the invoke URL
This can be done in the AWS Console. Navigate to the stages section and select 'prod'. You can then find the api invoke url. This will be needed to set up the GraphQL IDE (GraphiQL) and for the UI to invoke the lambda function What's next?GREAT! Your lambda and api are now ready for the front end! Head over to https://github.com/nikhilaravi/serverless-graphql-app to learn how to deploy the GraphiQL IDE to query your schema and the UI for the Jukebox app! What about tests?There are some example tests in the test folder for the GraphQL schema and services. You can run the tests with npm test The coverage isn't 100% yet but i'll be adding more tests soon!! TODO
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论