https://github.com/webnt-dev/aws-demo-api
AppSync CloudFormation AWS documentation.
Repository contains AWS resources to create basic API demo application:
- AppSync GraphQL service
- Schema and resolvers for GraphQL
- resolvers javaScript and VTL
- direct resolvers (using VTL) and pipelines using JavaScript
- JS resolvers validation (just commented example)
- AppSync caching (disabled by default in CF template)
- Connecting resolvers to
- DynamoDB
- Lambda
- SQS
- Testing VTL/JS resolvers/function time cost
- Lambdas
- simple subscription example (real-time)
Description of API calls, what they do.
Rename file to just sandbox.yml and fill your own information (region, client key, secret key).
Update paths for lambdaSources.
Bucked specified as installBucketName must already exists (cannot be created by this process).
File contains the stack itself. File is commented to understand purpose of every resource.
- run
npm installin all directories (aws, all lambda directories, tests) - you can install the stack from
awsdirectory runningnpm run sandbox
- runs linters
- compiles TS resolvers to JS
- build CloudFormation template from resources (graphql, JS resolvers and VTL resolvers)
- validates the template
- created or updates stack
- zips Lambdas code and copies those into installation bucket
- update Lambdas code
CloudFormation requires certain data to be included in the template: * GraphQL schema for AppSync * Code for resolvers templates or function templates / codes
Code/schema directly included is hard to read, TS code cannot be processed (linting, building) and template becomes quite large.
aws/stack/sandbox.yml contains placeholders for such data that are filled by installation script.
GraphQL schema is build by joining together all files from Definition property
For JS: File referenced in Code is used
For VTL: Files referenced in RequestMappingTemplate and ResponseMappingTemplate are used
For JS: File referenced in Code is used
For VTL: Files referenced in RequestMappingTemplate and ResponseMappingTemplate are used
Lambdas are defined without source code (just with placeholder source code).
aws/config/sandbox.template.yml contains Lambda resources code paths. Code in this path is zipped (into aws directory) and used
uploaded to installation bucket and used as source code (UpdateFunctionCodeCommand)
You can find simple subscription demo in tests
You can run queries against AppSync remotely (using AppSync -> -> Settings -> API URL as URL
and keys (again at Settings page) as x-api-key header)
or from console (using AppSync -> -> Queries)
Some test queries are located at aws/appsync/demo/AppSyncApi
Automated tests are located at tests folder (not done yet).
- Tests
- WebSockets / subscriptions
- Publish schema in API documentation
- Complete subscription example
This demo if focused only on AppSync itself and as such should not be used in production:
- you should not use API key for authentication (Cognito and/or IAM are much better options)
- API itself is not idempotent (there is no eventId or similar unique command (mutation) identifier making deduplication impossible
- etc.
2023-05-05
+ GraphQL tests added
2023-05-05
+ recipeDelete - delete recipe
2023-04-29 initial version
