DX: Make it easier to use API gateway base URL in environment variables
See original GitHub issueThis post http://www.goingserverless.com/blog/api-gateway-url outlines how to grab the base API gateway url from cloud-formation.
This is a pretty common url case and prevents folks from having to hardcode strings
It works but is god awful to write. No human should ever ever ever ever ever ever have to write:
{ "Fn::Join" : ["", [ "https://", { "Ref" : "ApiGatewayRestApi" }, ".execute-api.${self:custom.region}.amazonaws.com/${self:custom.stage}" ] ] }
Here is a working serverless.yml example:
service: the-service
custom:
stage: "${opt:stage, self:provider.stage}"
region: "${opt:region, self:provider.region}"
provider:
name: aws
runtime: nodejs6.10
environment:
IT_WORKS: { "Fn::Join" : ["", [ "https://", { "Ref" : "ApiGatewayRestApi" }, ".execute-api.${self:custom.region}.amazonaws.com/${self:custom.stage}" ] ] }
functions:
myFunc:
handler: handler.test
events:
- http:
path: whatever
method: post
cors: true
// hander.js
module.exports.test = (event, context, callback) => {
console.log('API URL IT_WORKS', process.env.IT_WORKS)
// now I can call other urls of service without hardcoding stuff
}
Suggestion: Make a shorthand variable to reference this instead of the verbose cloudformation.
Something like: ${apiGatewayUrl}
(or something)
Let’s make it easy to write and read! =)
Issue Analytics
- State:
- Created 6 years ago
- Reactions:20
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Setting up stage variables for a REST API deployment
To use a stage variable to customize the HTTP integration endpoint, you must first configure a stage variable of a specified name (for...
Read more >Reference Your API Gateway URL from within Your Code
If you've wanted to be able to use the URL of your service before you've deployed it then this is the video for...
Read more >S3 Bucket Integration for API Gateway - Terraform Registry
This example demonstrates how to create an S3 Proxy using AWS API Gateway. It takes you through listing the buckets of the API...
Read more >Connecting a web app to your PyTorch model using Amazon ...
Ideally, we could connect this URL directly to API Gateway. ... To do so, we should create an environment variable for the SageMaker...
Read more >Edge Functions are now available in Supabase
Your project's URLs, API keys, and database connection strings are made available as environment variables within your Function to make this ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
AN old topic but thought I’d share this and bump it so we close it if it’s not needed anymore, I use this and it works fine:
I’m closing it for two reasons:
Let me know if missed something