- Published on
OpenCage API integration with AWS Cloud
- Authors
- Name
- Arnaud Ferrand
- @arferrand
This post was previously published on DEV.TO on the 17th March 2021.
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:
- An AWS account to run a lambda function
- An OpenCage API Key
- NodeJS
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
2- Setup
cd /path/to/repository
npm install # or yarn install
Create an environment file containing the API Key (YOUR-API-KEY):
echo "OPENCAGE_API_KEY=YOUR-API-KEY" >> .env
3- Deploy And now, deploy the proxy with
npx serverless deploy
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
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'
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