Connecting your Amazon API Gateway to Apiable
This tutorial will guide you through the process of setting up the S3 bucket, and Firehose Stream using AWS CLI and AWS CDK. We’ll also cover how to set up the necessary tools, including Cygwin on Windows and Node.js (npm) using NVM. Let’s get started!
Precondition Setup
⚠️ The precondition setup is optional. If you have a Terminal or Cygwin, Node.js, AWS CLI and CDK installed, you can skip this part.
1. Install Cygwin on Windows
Cygwin allows you to run a Unix-like environment on Windows. Here's how to install it:
Go to the Cygwin website.
Click Download and run the setup file.
During installation, ensure you select the following packages:
curl
git
openssh
Complete the installation and open the Cygwin terminal.
2. Install Node.js and npm using NVM
For Mac/Unix Systems:
Open the Terminal app.
Install Homebrew if not already installed:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Use Homebrew to install NVM:
brew install nvm
Create an NVM directory and update your shell configuration file:
mkdir ~/.nvm echo 'export NVM_DIR="$HOME/.nvm"' >> ~/.zshrc echo '[ -s "/usr/local/opt/nvm/nvm.sh" ] && \. "/usr/local/opt/nvm/nvm.sh"' >> ~/.zshrc source ~/.zshrc
Install Node.js and npm using NVM:
nvm install node
For Windows:
Open Cygwin.
Install NVM by running:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
Update your Cygwin shell config file (e.g.,
~/.bashrc
) and add the following:export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
Reload the shell config file:
source ~/.bashrc
Install Node.js and npm using NVM:
nvm install node
3. Install AWS CLI
For Mac/Unix Systems:
In the terminal, run:
curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg" sudo installer -pkg AWSCLIV2.pkg -target /
Verify the installation:
aws --version
For Windows:
In the Cygwin terminal, run:
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" unzip awscliv2.zip sudo ./aws/install
Verify the installation:
aws --version
4. Install AWS CDK
In the terminal (Mac or Cygwin), run the following to install the AWS CDK:
npm install -g aws-cdk
Verify the installation:
cdk --version
5. Set AWS Key/Secret
Create the
.aws
directory and config files:mkdir -p ~/.aws touch ~/.aws/credentials
Open the
credentials
file in a text editor and add your AWS Access Key and Secret Key:[default] aws_access_key_id = YOUR_AWS_ACCESS_KEY_ID aws_secret_access_key = YOUR_AWS_SECRET_ACCESS_KEY
Save and close the file.
6. Run cdk bootstrap
In the terminal, run:
cdk bootstrap
This prepares your AWS account to use AWS CDK.
7. Clone the APIable CDK Repository
Open the terminal (Mac or Cygwin).
Run the following command to clone the repository:
git clone https://github.com/apiable/cdk cd cdk
9. Deploy the S3 Logs Bucket
Run the following command to install the S3 bucket where logs will be collected:
./deploy-apiable-logs-bucket.sh $AWS_ACCOUNT_ID $AWS_REGION $STACKNAME
Example:
./deploy-logs-bucket.sh 034444869755 eu-central-1 dev
Copy & Paste the outputs of the run into some editor, which will look similar to this
Please provide this information to Apiable support in order to complete the integration:
Region (e.g. eu-central-1)
S3 bucket name (e.g apiable-logs-dev )
ARN (e.g. arn:aws:iam...)
Send to support@apiable.io
10. Deploy the Firehose Stream
Take note of the ARN from the S3 bucket you created in the previous step.
Run the following command to install the Firehose stream:
./deploy-usagelogs.sh $AWS_ACCOUNT_ID $AWS_REGION $LOGS_BUCKET_ARN $STACKNAME
Example:
./deploy-usagelogs.sh 034444869755 eu-central-1 arn:aws:s3:::apiable-logs-dev dev
Copy & Paste the outputs of the run into some editor, which will look similar to this
11. Enable usage reporting in the gateway
Go to the API Gateway console and select the deployed Gateway
Select the API
Go to the Stages
Select the Stage
Go to the Logs/Tracing and click Edit
Enable "Custom access logging"
Insert the FirehoseArn from the Output of Step 10 into "Access log destination ARN".
Paste following pattern in the "Log format" field and click save. It MUST be one-line:
{"api_id": "$context.apiId","api_key": "$context.identity.apiKey","key_id": "$context.identity.apiKeyId","ip": "$context.identity.sourceIp","method": "$context.httpMethod","uri": "$context.path","response_size":"$context.responseLength","response_status": "$context.status","resource_id": "$context.resourceId","request_id": "$context.requestId","request_latency": "$context.responseLatency","request_time":"$context.requestTimeEpoch","stage": "$context.stage", "plan_id": "$context.authorizer.apiable_plan_id", "subscription_id": "$context.authorizer.apiable_subscription_id"}
You're All Set Up!
Now you have successfully set up the Apiable Gateway Role, S3 bucket, Firehose Stream, and Gateway API connection and enabled usage reporting. You are ready to start using the system with Apiable!