{"id":18539076,"url":"https://github.com/simov/grant-aws","last_synced_at":"2025-08-12T05:15:39.990Z","repository":{"id":66028223,"uuid":"282908777","full_name":"simov/grant-aws","owner":"simov","description":"AWS Lambda handler for Grant","archived":false,"fork":false,"pushed_at":"2021-01-04T09:43:45.000Z","size":20,"stargazers_count":16,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-26T09:41:50.232Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/simov.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":"2020-07-27T13:37:51.000Z","updated_at":"2024-02-18T14:17:16.000Z","dependencies_parsed_at":"2023-03-16T02:17:18.914Z","dependency_job_id":null,"html_url":"https://github.com/simov/grant-aws","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/simov/grant-aws","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simov%2Fgrant-aws","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simov%2Fgrant-aws/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simov%2Fgrant-aws/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simov%2Fgrant-aws/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simov","download_url":"https://codeload.github.com/simov/grant-aws/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simov%2Fgrant-aws/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270005591,"owners_count":24510939,"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","status":"online","status_checked_at":"2025-08-12T02:00:09.011Z","response_time":80,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-11-06T19:46:09.035Z","updated_at":"2025-08-12T05:15:39.966Z","avatar_url":"https://github.com/simov.png","language":"HCL","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# grant-aws\n\n\u003e _AWS Lambda handler for **[Grant]**_\n\n```js\nvar grant = require('grant').aws({\n  config: {/*Grant configuration*/}, session: {secret: 'grant'}\n})\n\nexports.handler = async (event) =\u003e {\n  var {redirect, response} = await grant(event)\n  return redirect || {\n    statusCode: 200,\n    headers: {'content-type': 'application/json'},\n    body: JSON.stringify(response)\n  }\n}\n```\n\n\u003e _Also available for [Azure], [Google Cloud], [Vercel]_\n\n\u003e _[ES Modules and TypeScript][grant-types]_\n\n---\n\n## Configuration\n\nThe `config` key expects your [**Grant** configuration][grant-config].\n\n## Routes\n\nGrant relies on the request path to determine the provider name and any static override being used. The following event keys are being used to determine the request path:\n\n| Gateway | Event | Key\n| :-:     | :-:   | :-\n| rest    | -     | event.requestContext.path\n| http    | v1    | event.path\n| http    | v2    | event.rawPath\n\nAdditionally the `prefix` specified in your Grant configuration is used to generate the correct `redirect_uri` in case it is not configured explicitly.\n\nHowever, AWS is inconsistent in the way it sets those values under different circumstances, and you may have to print those event keys and adjust your Grant configuration accordingly. A few known cases:\n\n### Default Domain\n\n```\nhttps://[id].execute-api.[region].amazonaws.com/[stage]/connect/google\nhttps://[id].execute-api.[region].amazonaws.com/[stage]/connect/google/callback\n```\n\nGateway | Event | Key                       | Value\n:-:     | :-:   | :-                        | :-\nrest    | -     | event.requestContext.path | `/stage/connect/google`\nhttp    | v1    | event.path                | `/stage/connect/google`\nhttp    | v2    | event.rawPath             | `/stage/connect/google`\n\n```json\n{\n  \"defaults\": {\n    \"origin\": \"https://[id].execute-api.[region].amazonaws.com\",\n    \"prefix\": \"/[stage]/connect\"\n  },\n  \"google\": {}\n}\n```\n\n### Custom Domain\n\n```\nhttps://amazing.com/connect/google\nhttps://amazing.com/connect/google/callback\n```\n\nGateway | Event | Key                       | Value\n:-:     | :-:   | :-                        | :-\nrest    | -     | event.requestContext.path | `/connect/google`\nhttp    | v1    | event.path                | `/connect/google`\nhttp    | v2    | event.rawPath             | `/stage/connect/google`\n\n##### REST API, HTTP API v1\n\n```json\n{\n  \"defaults\": {\n    \"origin\": \"https://amazing.com\",\n    \"prefix\": \"/connect\"\n  },\n  \"google\": {}\n}\n```\n\n##### HTTP API v2\n\n```json\n{\n  \"defaults\": {\n    \"origin\": \"https://amazing.com\",\n    \"prefix\": \"/stage/connect\"\n  },\n  \"google\": {\n    \"redirect_uri\": \"https://amazing.com/connect/google/callback\"\n  }\n}\n```\n\n### Custom Domain + Path Mapping\n\n```\nhttps://amazing.com/v1/connect/google\nhttps://amazing.com/v1/connect/google/callback\n```\n\nGateway | Event | Key                       | Value\n:-:     | :-:   | :-                        | :-\nrest    | -     | event.requestContext.path | `/v1/connect/google`\nhttp    | v1    | event.path                | `/v1/connect/google`\nhttp    | v2    | event.rawPath             | `/stage/connect/google`\n\n##### REST API, HTTP API v1\n\n```json\n{\n  \"defaults\": {\n    \"origin\": \"https://amazing.com\",\n    \"prefix\": \"/v1/connect\"\n  },\n  \"google\": {}\n}\n```\n\n##### HTTP API v2\n\n```json\n{\n  \"defaults\": {\n    \"origin\": \"https://amazing.com\",\n    \"prefix\": \"/stage/connect\"\n  },\n  \"google\": {\n    \"redirect_uri\": \"https://amazing.com/v1/connect/google/callback\"\n  }\n}\n```\n\n---\n\n## Local Routes\n\nWhen running locally the following routes can be used:\n\n```\nhttp://localhost:3000/[stage]/connect/google\nhttp://localhost:3000/[stage]/connect/google/callback\n```\n\n---\n\n## Session\n\nThe `session` key expects your session configuration:\n\nOption | Description\n:- | :-\n`name` | Cookie name, defaults to `grant`\n`secret` | Cookie secret, **required**\n`cookie` | [cookie] options, defaults to `{path: '/', httpOnly: true, secure: false, maxAge: null}`\n`store` | External session store implementation\n\n#### NOTE:\n\n- The default cookie store is used unless you specify a `store` implementation!\n- Using the default cookie store **may leak private data**!\n- Implementing an external session store is recommended for production deployments!\n\nExample session store implementation using [Firebase]:\n\n```js\nvar request = require('request-compose').client\n\nvar path = process.env.FIREBASE_PATH\nvar auth = process.env.FIREBASE_AUTH\n\nmodule.exports = {\n  get: async (sid) =\u003e {\n    var {body} = await request({\n      method: 'GET', url: `${path}/${sid}.json`, qs: {auth},\n    })\n    return body\n  },\n  set: async (sid, json) =\u003e {\n    await request({\n      method: 'PATCH', url: `${path}/${sid}.json`, qs: {auth}, json,\n    })\n  },\n  remove: async (sid) =\u003e {\n    await request({\n      method: 'DELETE', url: `${path}/${sid}.json`, qs: {auth},\n    })\n  },\n}\n```\n\n---\n\n## Handler\n\nThe AWS Lambda handler for Grant accepts:\n\nArgument | Type | Description\n:- | :- | :-\n`event` | **required** | The AWS Lambda event object\n`state` | optional | [Dynamic State][grant-dynamic-state] object `{dynamic: {..Grant configuration..}}`\n\nThe AWS Lambda handler for Grant returns:\n\nParameter | Availability | Description\n:- | :- | :-\n`session` | Always | The session store instance, `get`, `set` and `remove` methods can be used to manage the Grant session\n`redirect` | On redirect only | HTTP redirect controlled by Grant, your lambda have to return this object when present\n`response` | Based on transport | The [response data][grant-response-data], available for [transport-state][example-transport-state] and [transport-session][example-transport-session] only\n\n---\n\n## Examples\n\nExample | Session | Callback λ\n:- | :- | :-\n`transport-state` | Cookie Store | ✕\n`transport-querystring` | Cookie Store | ✓\n`transport-session` | Firebase Session Store | ✓\n`dynamic-state` | Firebase Session Store | ✕\n\n\u003e _Different session store types were used for example purposes only._\n\n#### Configuration\n\nAll variables at the top of the [`Makefile`][example-makefile] with value set to `...` have to be configured:\n\n- `profile` - `AWS_PROFILE` to use for managing AWS resources, not used for local development\n\n- `firebase_path` - [Firebase] path of your database, required for [transport-session][example-transport-session] and [dynamic-state][example-dynamic-state] examples\n\n```\nhttps://[project].firebaseio.com/[prefix]\n```\n\n- `firebase_auth` - [Firebase] auth key of your database, required for [transport-session][example-transport-session] and [dynamic-state][example-dynamic-state] examples\n\n```json\n{\n  \"rules\": {\n    \".read\": \"auth == '[key]'\",\n    \".write\": \"auth == '[key]'\"\n  }\n}\n```\n\n- `api_type` - defaults to `http-api`, available for `rest-api` as well\n\n- `event_format` - defaults to `1.0`, available for `2.0` as well, applicable for `http-api`\n\nAll variables can be passed as arguments to `make` as well:\n\n```bash\nmake plan example=transport-querystring ...\n```\n\n---\n\n## Develop\n\n```bash\n# build example locally\nmake build-dev\n# run example locally\nmake run-dev\n```\n\n---\n\n## Deploy\n\n```bash\n# build Grant lambda for deployment\nmake build-grant\n# build callback lambda for transport-querystring and transport-session examples\nmake build-callback\n# execute only once\nmake init\n# plan before every deployment\nmake plan\n# apply plan for deployment\nmake apply\n# cleanup resources\nmake destroy\n```\n\n---\n\n  [Grant]: https://github.com/simov/grant\n  [AWS]: https://github.com/simov/grant-aws\n  [Azure]: https://github.com/simov/grant-azure\n  [Google Cloud]: https://github.com/simov/grant-gcloud\n  [Vercel]: https://github.com/simov/grant-vercel\n\n  [cookie]: https://www.npmjs.com/package/cookie\n  [Firebase]: https://firebase.google.com/\n\n  [grant-config]: https://github.com/simov/grant#configuration\n  [grant-dynamic-state]: https://github.com/simov/grant#dynamic-state\n  [grant-response-data]: https://github.com/simov/grant#callback-data\n  [grant-types]: https://github.com/simov/grant#misc-es-modules-and-typescript\n\n  [example-makefile]: https://github.com/simov/grant-aws/tree/master/Makefile\n  [example-transport-state]: https://github.com/simov/grant-aws/tree/master/examples/transport-state\n  [example-transport-querystring]: https://github.com/simov/grant-aws/tree/master/examples/transport-querystring\n  [example-transport-session]: https://github.com/simov/grant-aws/tree/master/examples/transport-session\n  [example-dynamic-state]: https://github.com/simov/grant-aws/tree/master/examples/dynamic-state\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimov%2Fgrant-aws","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimov%2Fgrant-aws","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimov%2Fgrant-aws/lists"}