DEV Community

Cover image for OpenCage API integration with AWS Cloud
Arnaud Ferrand
Arnaud Ferrand

Posted on • Updated on

OpenCage API integration with AWS Cloud

A few years ago, I started to enjoy serverless, or what we can more precisely call Function As A Service (FAAS). I created a tutorial "How to simply wrap the OpenCage Geocoding API into an AWS Lambda function".

NodeJS and AWS lambda have evolved, the tutorial is still valid to learn how to use the serverless framework with AWS Lambda functions; today this post is more about quicky deploy an OpenCage Geocoding API proxy in your own AWS infrastructure.

Let's get started with the usual prerequisites:

The three steps will take less than 5 minutes to complete
1-Clone
2-Setup
3-Deploy

1- Clone this repository

git clone https://github.com/tsamaya/opencage-lambda-proxy.git
# or use the ssh version
git clone git@github.com:tsamaya/opencage-lambda-proxy.git
Enter fullscreen mode Exit fullscreen mode

2- Setup

cd /path/to/repository

npm install # or yarn install
Enter fullscreen mode Exit fullscreen mode

Create an environment file containing the API Key (YOUR-API-KEY):

echo "OPENCAGE_API_KEY=YOUR-API-KEY" >> .env
Enter fullscreen mode Exit fullscreen mode

3- Deploy
And now, deploy the proxy with

npx serverless deploy
Enter fullscreen mode Exit fullscreen mode

it will output

Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Creating Stack...
Serverless: Checking Stack create progress...
........
Serverless: Stack create finished...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service opencage-lambda-proxy.zip file to S3 (1.54 MB)...
Serverless: Validating template...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
..............................
Serverless: Stack update finished...
Service Information
service: opencage-lambda-proxy
stage: dev
region: eu-west-1
stack: opencage-lambda-proxy-dev
resources: 11
api keys:
  None
endpoints:
  GET - https://xxxxxxxxxx.execute-api.eu-west-1.amazonaws.com/geocode
functions:
  geocode: opencage-lambda-proxy-dev-geocode
layers:
  None
Enter fullscreen mode Exit fullscreen mode

The proxy is ready to use within your applications.

You can test this curl command (updating the xxxxxxxxxx with the values seen in the deploy command)

curl 'https://xxxxxxxxxx.execute-api.eu-west-1.amazonaws.com/geocode?q=lyon'
Enter fullscreen mode Exit fullscreen mode

That is it, please enjoy it and let me know if you have any questions.

Resources

cover image: Photo by Lucas George Wendt on Unsplash

Top comments (0)