Multiple API Gateway instances, one lambda function
up vote
1
down vote
favorite
I am trying to build a system where multiple APIs gateway instances should execute the same lambda function.
My problem is that I would like to change only the lambda configuration in function of the API gateway used.
Let's take the name of a database as an example that should change if the lambda is being triggered from one API or the other.
Example:
API Gateways:
https://my-first-api-gateway.execute-api.eu-west-1.amazonaws.com
https://my-second-api-gateway.execute-api.eu-west-1.amazonaws.com
I then have one lambda function being called by the two APIs: say_hello
.
This function has to retrieve a quote from a database. If the function has been called from my-first-api-gateway
the lambda function has to use my_first_database
and if the function has been called from my-second-api-gateway
, it has to use my_second_database
.
The only solution I came with is to deploy as many lambda functions as I have API Gateways. And then use environment variables to store my database name.
I don't like my solution because when I update a single line of code I'll have to redeploy all of my lambda functions.. (if I have 300 different databases to use, that would mean to update 300 lambda functions at once..)
Thank you for your ideas on this subject!
amazon-web-services lambda aws-lambda aws-api-gateway
add a comment |
up vote
1
down vote
favorite
I am trying to build a system where multiple APIs gateway instances should execute the same lambda function.
My problem is that I would like to change only the lambda configuration in function of the API gateway used.
Let's take the name of a database as an example that should change if the lambda is being triggered from one API or the other.
Example:
API Gateways:
https://my-first-api-gateway.execute-api.eu-west-1.amazonaws.com
https://my-second-api-gateway.execute-api.eu-west-1.amazonaws.com
I then have one lambda function being called by the two APIs: say_hello
.
This function has to retrieve a quote from a database. If the function has been called from my-first-api-gateway
the lambda function has to use my_first_database
and if the function has been called from my-second-api-gateway
, it has to use my_second_database
.
The only solution I came with is to deploy as many lambda functions as I have API Gateways. And then use environment variables to store my database name.
I don't like my solution because when I update a single line of code I'll have to redeploy all of my lambda functions.. (if I have 300 different databases to use, that would mean to update 300 lambda functions at once..)
Thank you for your ideas on this subject!
amazon-web-services lambda aws-lambda aws-api-gateway
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I am trying to build a system where multiple APIs gateway instances should execute the same lambda function.
My problem is that I would like to change only the lambda configuration in function of the API gateway used.
Let's take the name of a database as an example that should change if the lambda is being triggered from one API or the other.
Example:
API Gateways:
https://my-first-api-gateway.execute-api.eu-west-1.amazonaws.com
https://my-second-api-gateway.execute-api.eu-west-1.amazonaws.com
I then have one lambda function being called by the two APIs: say_hello
.
This function has to retrieve a quote from a database. If the function has been called from my-first-api-gateway
the lambda function has to use my_first_database
and if the function has been called from my-second-api-gateway
, it has to use my_second_database
.
The only solution I came with is to deploy as many lambda functions as I have API Gateways. And then use environment variables to store my database name.
I don't like my solution because when I update a single line of code I'll have to redeploy all of my lambda functions.. (if I have 300 different databases to use, that would mean to update 300 lambda functions at once..)
Thank you for your ideas on this subject!
amazon-web-services lambda aws-lambda aws-api-gateway
I am trying to build a system where multiple APIs gateway instances should execute the same lambda function.
My problem is that I would like to change only the lambda configuration in function of the API gateway used.
Let's take the name of a database as an example that should change if the lambda is being triggered from one API or the other.
Example:
API Gateways:
https://my-first-api-gateway.execute-api.eu-west-1.amazonaws.com
https://my-second-api-gateway.execute-api.eu-west-1.amazonaws.com
I then have one lambda function being called by the two APIs: say_hello
.
This function has to retrieve a quote from a database. If the function has been called from my-first-api-gateway
the lambda function has to use my_first_database
and if the function has been called from my-second-api-gateway
, it has to use my_second_database
.
The only solution I came with is to deploy as many lambda functions as I have API Gateways. And then use environment variables to store my database name.
I don't like my solution because when I update a single line of code I'll have to redeploy all of my lambda functions.. (if I have 300 different databases to use, that would mean to update 300 lambda functions at once..)
Thank you for your ideas on this subject!
amazon-web-services lambda aws-lambda aws-api-gateway
amazon-web-services lambda aws-lambda aws-api-gateway
asked Nov 8 at 13:15
Hammerbot
5,07331647
5,07331647
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
If you use a Lambda-Proxy
integration you should be fine.
Full details of the event can be found here, however critically the headers Host
, origin
and Referer
all point the the API Gateway uri:
"headers": {
"Host": "j3ap25j034.execute-api.eu-west-2.amazonaws.com",
"origin": "https://j3ap25j034.execute-api.eu-west-2.amazonaws.com",
"Referer": "https://j3ap25j034.execute-api.eu-west-2.amazonaws.com/dev/"
}
Therefore it should be fairly trivial for you to branch/look-up your database behaviour from this information.
Thank you for your response. What would you use to make this lookup then? Where would you store the map between the URL of the API gateway and databases names?
– Hammerbot
Nov 8 at 13:36
1
I suspect that depends a bit on how much you're looking to update it. If it's relatively infrequent update you might just store it in code. If not S3 (you can have a JSON file you read and cache), or Dynamo (key is execute-api id) are both contenters. Dynamo has an edge in that it's a bit faster (precise lookup) and presents a reasonable UI for editing in the AWS console.
– thomasmichaelwallace
Nov 8 at 13:54
Hi, just in case someone gets on this question some day: aws.amazon.com/blogs/compute/… stage variables allow passing variables from api gateway to lambda. It looks much more clean to me :) Credit to a redditer for sending me this link
– Hammerbot
Nov 9 at 10:28
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
If you use a Lambda-Proxy
integration you should be fine.
Full details of the event can be found here, however critically the headers Host
, origin
and Referer
all point the the API Gateway uri:
"headers": {
"Host": "j3ap25j034.execute-api.eu-west-2.amazonaws.com",
"origin": "https://j3ap25j034.execute-api.eu-west-2.amazonaws.com",
"Referer": "https://j3ap25j034.execute-api.eu-west-2.amazonaws.com/dev/"
}
Therefore it should be fairly trivial for you to branch/look-up your database behaviour from this information.
Thank you for your response. What would you use to make this lookup then? Where would you store the map between the URL of the API gateway and databases names?
– Hammerbot
Nov 8 at 13:36
1
I suspect that depends a bit on how much you're looking to update it. If it's relatively infrequent update you might just store it in code. If not S3 (you can have a JSON file you read and cache), or Dynamo (key is execute-api id) are both contenters. Dynamo has an edge in that it's a bit faster (precise lookup) and presents a reasonable UI for editing in the AWS console.
– thomasmichaelwallace
Nov 8 at 13:54
Hi, just in case someone gets on this question some day: aws.amazon.com/blogs/compute/… stage variables allow passing variables from api gateway to lambda. It looks much more clean to me :) Credit to a redditer for sending me this link
– Hammerbot
Nov 9 at 10:28
add a comment |
up vote
2
down vote
accepted
If you use a Lambda-Proxy
integration you should be fine.
Full details of the event can be found here, however critically the headers Host
, origin
and Referer
all point the the API Gateway uri:
"headers": {
"Host": "j3ap25j034.execute-api.eu-west-2.amazonaws.com",
"origin": "https://j3ap25j034.execute-api.eu-west-2.amazonaws.com",
"Referer": "https://j3ap25j034.execute-api.eu-west-2.amazonaws.com/dev/"
}
Therefore it should be fairly trivial for you to branch/look-up your database behaviour from this information.
Thank you for your response. What would you use to make this lookup then? Where would you store the map between the URL of the API gateway and databases names?
– Hammerbot
Nov 8 at 13:36
1
I suspect that depends a bit on how much you're looking to update it. If it's relatively infrequent update you might just store it in code. If not S3 (you can have a JSON file you read and cache), or Dynamo (key is execute-api id) are both contenters. Dynamo has an edge in that it's a bit faster (precise lookup) and presents a reasonable UI for editing in the AWS console.
– thomasmichaelwallace
Nov 8 at 13:54
Hi, just in case someone gets on this question some day: aws.amazon.com/blogs/compute/… stage variables allow passing variables from api gateway to lambda. It looks much more clean to me :) Credit to a redditer for sending me this link
– Hammerbot
Nov 9 at 10:28
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
If you use a Lambda-Proxy
integration you should be fine.
Full details of the event can be found here, however critically the headers Host
, origin
and Referer
all point the the API Gateway uri:
"headers": {
"Host": "j3ap25j034.execute-api.eu-west-2.amazonaws.com",
"origin": "https://j3ap25j034.execute-api.eu-west-2.amazonaws.com",
"Referer": "https://j3ap25j034.execute-api.eu-west-2.amazonaws.com/dev/"
}
Therefore it should be fairly trivial for you to branch/look-up your database behaviour from this information.
If you use a Lambda-Proxy
integration you should be fine.
Full details of the event can be found here, however critically the headers Host
, origin
and Referer
all point the the API Gateway uri:
"headers": {
"Host": "j3ap25j034.execute-api.eu-west-2.amazonaws.com",
"origin": "https://j3ap25j034.execute-api.eu-west-2.amazonaws.com",
"Referer": "https://j3ap25j034.execute-api.eu-west-2.amazonaws.com/dev/"
}
Therefore it should be fairly trivial for you to branch/look-up your database behaviour from this information.
answered Nov 8 at 13:30
thomasmichaelwallace
2,0851816
2,0851816
Thank you for your response. What would you use to make this lookup then? Where would you store the map between the URL of the API gateway and databases names?
– Hammerbot
Nov 8 at 13:36
1
I suspect that depends a bit on how much you're looking to update it. If it's relatively infrequent update you might just store it in code. If not S3 (you can have a JSON file you read and cache), or Dynamo (key is execute-api id) are both contenters. Dynamo has an edge in that it's a bit faster (precise lookup) and presents a reasonable UI for editing in the AWS console.
– thomasmichaelwallace
Nov 8 at 13:54
Hi, just in case someone gets on this question some day: aws.amazon.com/blogs/compute/… stage variables allow passing variables from api gateway to lambda. It looks much more clean to me :) Credit to a redditer for sending me this link
– Hammerbot
Nov 9 at 10:28
add a comment |
Thank you for your response. What would you use to make this lookup then? Where would you store the map between the URL of the API gateway and databases names?
– Hammerbot
Nov 8 at 13:36
1
I suspect that depends a bit on how much you're looking to update it. If it's relatively infrequent update you might just store it in code. If not S3 (you can have a JSON file you read and cache), or Dynamo (key is execute-api id) are both contenters. Dynamo has an edge in that it's a bit faster (precise lookup) and presents a reasonable UI for editing in the AWS console.
– thomasmichaelwallace
Nov 8 at 13:54
Hi, just in case someone gets on this question some day: aws.amazon.com/blogs/compute/… stage variables allow passing variables from api gateway to lambda. It looks much more clean to me :) Credit to a redditer for sending me this link
– Hammerbot
Nov 9 at 10:28
Thank you for your response. What would you use to make this lookup then? Where would you store the map between the URL of the API gateway and databases names?
– Hammerbot
Nov 8 at 13:36
Thank you for your response. What would you use to make this lookup then? Where would you store the map between the URL of the API gateway and databases names?
– Hammerbot
Nov 8 at 13:36
1
1
I suspect that depends a bit on how much you're looking to update it. If it's relatively infrequent update you might just store it in code. If not S3 (you can have a JSON file you read and cache), or Dynamo (key is execute-api id) are both contenters. Dynamo has an edge in that it's a bit faster (precise lookup) and presents a reasonable UI for editing in the AWS console.
– thomasmichaelwallace
Nov 8 at 13:54
I suspect that depends a bit on how much you're looking to update it. If it's relatively infrequent update you might just store it in code. If not S3 (you can have a JSON file you read and cache), or Dynamo (key is execute-api id) are both contenters. Dynamo has an edge in that it's a bit faster (precise lookup) and presents a reasonable UI for editing in the AWS console.
– thomasmichaelwallace
Nov 8 at 13:54
Hi, just in case someone gets on this question some day: aws.amazon.com/blogs/compute/… stage variables allow passing variables from api gateway to lambda. It looks much more clean to me :) Credit to a redditer for sending me this link
– Hammerbot
Nov 9 at 10:28
Hi, just in case someone gets on this question some day: aws.amazon.com/blogs/compute/… stage variables allow passing variables from api gateway to lambda. It looks much more clean to me :) Credit to a redditer for sending me this link
– Hammerbot
Nov 9 at 10:28
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53208525%2fmultiple-api-gateway-instances-one-lambda-function%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown