{"id":22127903,"url":"https://github.com/sashee/appsync-lambda-auth","last_synced_at":"2026-01-04T17:06:08.977Z","repository":{"id":138842058,"uuid":"462692872","full_name":"sashee/appsync-lambda-auth","owner":"sashee","description":"Lambda authorizer for AppSync example","archived":false,"fork":false,"pushed_at":"2022-04-04T08:21:51.000Z","size":24,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-26T19:37:29.342Z","etag":null,"topics":["appsync","aws","graphql","terraform"],"latest_commit_sha":null,"homepage":"https://advancedweb.hu/how-to-use-lambda-authorization-with-appsync/","language":"HCL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sashee.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-02-23T10:47:50.000Z","updated_at":"2023-05-06T14:54:31.000Z","dependencies_parsed_at":"2023-03-13T10:52:43.221Z","dependency_job_id":null,"html_url":"https://github.com/sashee/appsync-lambda-auth","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sashee%2Fappsync-lambda-auth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sashee%2Fappsync-lambda-auth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sashee%2Fappsync-lambda-auth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sashee%2Fappsync-lambda-auth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sashee","download_url":"https://codeload.github.com/sashee/appsync-lambda-auth/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244892350,"owners_count":20527432,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["appsync","aws","graphql","terraform"],"created_at":"2024-12-01T17:22:16.353Z","updated_at":"2026-01-04T17:06:08.947Z","avatar_url":"https://github.com/sashee.png","language":"HCL","readme":"# Lambda authorizer for AppSync\n\nThis repository is a demonstration on how to use a Lambda function as an authorization for an AppSync API.\n\nHere, the schema has *Documents* and *Files* and users need a *Token* to make requests to the API. For each of these tokens, we can:\n\n* Deny fields (```token1``` can not read the documents' text)\n* Allow only certain queries (```token1``` can not read any files)\n* Restrict access to documents by id (```token1``` can only read ```doc1``` but not ```doc2```)\n\n```mermaid\nclassDiagram\n    class token1 {\n        denied_fields: Document.text\n        allowed_queries: document\n        documents: doc1\n    }\n    class token2 {\n        denied_fields: \n        allowed_queries: document, file\n        documents: doc1, doc2\n    }\n    class doc1 {\n        \u003c\u003cDocument\u003e\u003e\n        title\n        text\n    }\n    class doc2 {\n        \u003c\u003cDocument\u003e\u003e\n        title\n        text\n    }\n    class file1 {\n        \u003c\u003cFile\u003e\u003e\n        name\n        url\n    }\n    token1 --\u003e doc1: title only\n    token2 --\u003e doc1\n    token2 --\u003e doc2\n    token2 --\u003e file1\n```\n\n## Prerequisites\n\n* AWS account\n* Terraform installed and configured for AWS\n\n## Install\n\n* ```terraform init```\n* ```terraform apply```\n\n## Use\n\n* Go to the AppSync console, select the *Queries* tab\n* Fetch ```doc1``` using ```token1```:\n\n```graphql\nquery MyQuery {\n  document(id: \"doc1\") {\n    id\n    title\n  }\n}\n```\n\n![image](https://user-images.githubusercontent.com/82075/155486833-270a2eb5-8353-48ca-b88b-5faee6ceb0b2.png)\n\n### Denied fields\n\n* Try to fetch the document ```text```:\n\n```graphql\nquery MyQuery {\n  document(id: \"doc1\") {\n    id\n    title\n    text\n  }\n}\n```\n\n**Unauthorized**\n\nBut with ```token2``` it works:\n\n```json\n{\n  \"data\": {\n    \"document\": {\n      \"id\": \"doc1\",\n      \"title\": \"Document 1\",\n      \"text\": \"Text for document 1\"\n    }\n  }\n}\n```\n\n### No access to the ```file``` query\n\n* Try to fetch a *file*:\n\n```graphql\nquery MyQuery {\n  file(id: \"file1\") {\n    id\n    name\n    url\n  }\n}\n```\n\n* ```token1``` =\u003e **Unauthorized**\n* ```token2``` =\u003e works\n\n### Document-level access control\n\n* Try to access ```doc2```:\n\n```graphql\nquery MyQuery {\n  document(id: \"doc2\") {\n    id\n    title\n  }\n}\n```\n\n* ```token1``` =\u003e **Unauthorized**\n* ```token2``` =\u003e works\n\n## Cleanup\n\n* ```terraform destroy```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsashee%2Fappsync-lambda-auth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsashee%2Fappsync-lambda-auth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsashee%2Fappsync-lambda-auth/lists"}