Set Up With AWS

The Moesif Developer Portal can be used with a running instance of AWS API Gateway. To integrate Moesif and AWS API Gateway, you can follow our guide that covers integrating Moesif and AWS API Gateway in detail. Alternatively, you can also check out our integration documentation for Tyk if you’re already an experienced AWS user. Once you have the integration set, you’ll be able to complete the rest of the AWS setup for the Developer Portal.

Add The Auth0 Authorizer to AWS API Gateway

In order for the Moesif Developer Portal and Billing Meter to work correctly, a custom Lambda Authorizer is required on the AWS API Gateway endpoint you want to monetize. The code for the Authorizer is contained within the dev-portal-authorizer project in the Moesif Developer Portal code. Once you have the project opened, in a terminal pointing to the dev-portal-authorizer directory, do the following:

  • Run npm install to install the project’s dependencies.
  • After the dependencies are installed, zip up the project using npm run zip.
    • From this command, an file will be created in the root directory of the authorizer project.
  • Next, log into AWS Lambda, and from the main screen, click Create function in the top-right corner.
  • On the Create function screen:
    • Select Author from scratch
    • Set the Function name field as Auth0Authorizer
    • Choose Node.js 18.x as the Runtime and x86_64 as the Architecture
    • Everything else can stay as the default and then you’ll click Create function
  • On the Auth0Authorizer screen, under Code source, click the Upload from dropdown and select .zip file.
  • In the modal that appears, either drop your .zip file onto it or select it from the file explorer by clicking the Upload button. Then click Save to load the .zip code.

In AWS API Gateway, we will create the Authorizer by clicking on Authorizers in the left-side menu. On the Authorizers screen, do the following:

  • Click Create New Authorizer
  • Add our Name as Auth0_Authorizer
  • Select the type as Lambda
  • Set the Lambda Event Payload as Token
  • Set the Token Source as Authorization
  • The rest of the fields can be left as their defaults, and you can click Create to create the Authorizer.

Next, we will add the Authorizer to the endpoint. This is done by going to Resources in the left-side menu, clicking on the desired endpoint, and bringing up the Method Execution screen.

On this screen, do the following:

  • Click on Method Request
  • Under Settings > Authorizer, click the Edit (pencil) icon and select Auth0_Authorizer. Click the checkmark to save the setting.
  • Make sure that API Key Required is set to false

Lastly, We need to add our variable in the stage’s log format to ensure that the Company/Subscription is correctly mapped in Moesif. To do this, perform the following:

  • Select the appropriate stage from the list in Stages in the left-side menu.
  • On the Stage Editor screen, click on the Logs/Tracing tab.
  • Under Custom Access Logging > Log Format, paste in the log format from the my-dev-portal-authorizer/aws-config/CustomAccessLogging_LogFormat.json file.
    • The key here is that the "principalId": "$context.authorizer.principalId" formatter is included to ensure that the Stripe data is correctly attributed to the request in Moesif.

Configuring The .env File

In the my-dev-portal-api project, populate the AWS_INVOKE_URL. For this value, you’ll need to grab the Invoke URL from your AWS API gateway instance. To find this value, go to your API Gateway instance, click on Stages, and then select the appropriate stage. On the Stage Editor screen, grab the Invoke URL and paste the value into AWS_INVOKE_URL.

Connecting AWS To Moesif

For the Developer Portal flow to work correctly, you’ll need to get analytics flowing into Moesif from AWS API Gateway. For instructions on how to integrate AWS API Gateway and Moesif, you can reference our integration documentation or a more in-depth step-by-step approach in our integration guide.