This project is about AWS lambda authorizer. That's mean you can secure your AWS APIGateway API's with custom authorization. You can use Auth0 or any other authorization provider that uses JWT tokens.
This project can be used as base for your next project. Everything has setup, create your REST API, pass on the lambda authorizer, just provide the details in auth.config.
This project is based on the following.
- AWS APIGateway
- Lambda authorizer
- NodeJs
- Typescript
- Infrastructure as a code, AWS CDK.
Install Nodejs 18.X.X or above + & Typescript 5.X.X. Follow the instructions
Prerequisites
-
NodeJs with Typescriptnodejs-with-typescript
-
npm install npm@latest -gnpm install typescript --save-dev -
AWS Cli confgiure as well with your AWS credentials.
1- Clone the repo
git clone git@github.com:m3dcodie/lambda-authorizer-typescript.git
2- Install NPM packages
npm install
3- Bootstrap
Bootstrapping is the process of preparing an environment for deployment. Bootstrapping is a one-time action that you must perform for every environment that you deploy resources into.
This file infrastructure/cdk-bootstrap/cdk.yaml contains the permissions neccessary to deploy this project into AWS account.
You can configure AWS account and AWS region to bootstrap in this file infrastructure/cdk-bootstrap/bootstrap.sh.
4- Assume the AWS role
awsume <profile>
Rename the file functions/authorizer/auth-example.json to auth.json. Update the below.
{
"audience": "",
"jwksUri": "https://<>/.well-known/jwks.json",
"tokenIssuer": "https://<>/"
}
cd infrastructure/cdk-bootstrap/
./bootstrap.sh [profile]
#set permissions if required
chmod 755 ./bootstrap.sh`
5- Deploy the solution
- `npm run build` compile typescript to js
- `cd infrastructure/app/deploy1/`
- Modify the file
`vi infrastructure/app/deploy1/cdk.context.json`
Update with your account and other tag details.
- `npx cdk deploy ApiCdkStack --profile [profile name]`
Confirm the changes with `y`.
Once deployed surccessfully, the CDK will output the API gateway endpoint or you can get from AWS APIgateway console.
Once you got Bearer token.
curl --request GET \ --url http://path_to_your_api/ \ --header 'authorization: Bearer <token here>'
or through AWS Gateway AWS APIGateway
- [] Changelog
- [] CI/CD pipelines
- [] Class & functions comments
- [] More unit tests
Distributed under the MIT License. See LICENCE.md for more information.
Suhail - m3d.suhail@gmail.com
Project Link: https://github.com/m3dcodie/lambda-authorizer-typescript