Set up API Gateway

We create a REST API with two routes and attach a Cognito JWT Authorizer to protect GET /songs.


1. Create the API

  1. Go to API Gateway ConsoleCreate API
  2. Select REST APIBuild

Create API

  1. Configure:
    • API name: workshop-api
    • Endpoint type: Regional

Configure API

  1. Click Create API. You will see the root resource /.

Root resource


2. Create resources and methods

/login resource

  1. Select the root /ActionsCreate Resource
  2. Resource name: loginCreate Resource

Create login resource

  1. Select /loginActionsCreate MethodPOST → ✓

  2. Configure:

    • Integration type: Lambda Function
    • Lambda proxy integration: ✓ (checked)
    • Lambda function: loginFunction
  3. Click SaveOK to grant permission

Create POST /login

/songs resource

  1. Select the root /ActionsCreate Resource

  2. Resource name: songsCreate Resource

  3. Select /songsActionsCreate MethodGET → ✓

  4. Configure:

    • Integration type: Lambda Function
    • Lambda proxy integration: ✓ (checked)
    • Lambda function: getSongsFunction
  5. Click SaveOK

Create GET /songs


3. Create Cognito Authorizer

This authorizer will validate the JWT token on every request to GET /songs.

  1. In the left sidebar → AuthorizersCreate New Authorizer
  2. Configure:
    • Name: CognitoAuthorizer
    • Type: Cognito
    • Cognito User Pool: select workshop-pool
    • Token source: Authorization

Create Cognito Authorizer Create Cognito Authorizer Create Cognito Authorizer

  1. Click Create
  2. Click Test → enter the idToken from a login call → verify it returns 200

4. Attach the Authorizer to GET /songs

  1. Click on /songsGET method
  2. Click Method Request
  3. Under Authorization, select CognitoAuthorizer from the dropdown
  4. Click the ✓ checkmark to save

Attach authorizer Attach authorizer result

Now GET /songs requires a valid JWT token. POST /login remains public.


5. Enable CORS

For each resource (/login and /songs):

  1. Select the resource → ActionsEnable CORS
  2. Keep defaults → Enable CORS and replace existing CORS headersYes

Enable CORS Enable CORS confirm


6. Deploy the API

  1. ActionsDeploy API
  2. Configure:
    • Deployment stage: [New Stage]
    • Stage name: dev

Deploy API

  1. Click Deploy
  2. Copy the Invoke URL — it looks like: https://xxxxxxxxxx.execute-api.us-east-1.amazonaws.com/dev

Save this URL. You will use it in the Testing section.