Making an HTTPs request on AWS ApiGatewayV2 websocket connection to Respond, or Delete itHow is an HTTP POST request made in node.js?How to extract request http headers from a request using NodeJS connectHTTP Response to a GET request has undefined bodyCalling Laravel Routes hosted on AWS Lambda using AWS API Gatewayhow to process json post request with nodejs http (no express framework)?AWS S3 static site CORS jquery ajax POST to API GatewayAWS API Gateway Lambda Function with Cognito authentication returns 415 Unsupported Media Typeapigateway websocket sqs integrationAWS HTTP API to WebSocket API Bridge / Async LambdaLog Api Gateway request/response body/headers to ElasticSearch
How to calculate the power level of a Commander deck?
Do I need to declare engagement ring bought in UK when flying on holiday to US?
Fantasy Military Arms and Armor: the Dwarven Grand Armory
What are the map units that WGS84 uses?
How should Thaumaturgy's "three times as loud as normal" be interpreted?
Entering the US with dual citizenship but US passport is long expired?
Can you create water inside someone's mouth?
Golfball Dimples on spaceships (and planes)?
Did the US Climate Reference Network Show No New Warming Since 2005 in the US?
Can taking my 1-week-old on a 6-7 hours journey in the car lead to medical complications?
Friend is very nit picky about side comments I don't intend to be taken too seriously
Does the Giant Toad's Swallow acid damage take effect only at the start of its next turn?
Why are some hotels asking you to book through Booking.com instead of matching the price at the front desk?
What would happen if you robbed the momentum from a falling object?
Did the Byzantines ever attempt to move their capital to Rome?
Why does the UK Prime Minister need the permission of Parliament to call a general election?
If I have an accident, should I file a claim with my car insurance company?
Male viewpoint in an erotic novel
Matlab fmincon for a problem with many nonlinear constraints
Why does 8 bit truecolor use only 2 bits for blue?
French equivalent of "my cup of tea"
These roommates throw strange parties
SQL Always On COPY ONLY backups - what's the point if I cant restore the AG from these backups?
Examples where "thin + thin = nice and thick"
Making an HTTPs request on AWS ApiGatewayV2 websocket connection to Respond, or Delete it
How is an HTTP POST request made in node.js?How to extract request http headers from a request using NodeJS connectHTTP Response to a GET request has undefined bodyCalling Laravel Routes hosted on AWS Lambda using AWS API Gatewayhow to process json post request with nodejs http (no express framework)?AWS S3 static site CORS jquery ajax POST to API GatewayAWS API Gateway Lambda Function with Cognito authentication returns 415 Unsupported Media Typeapigateway websocket sqs integrationAWS HTTP API to WebSocket API Bridge / Async LambdaLog Api Gateway request/response body/headers to ElasticSearch
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
UPDATE
This issue is partially resolved, the problem now lies in authenticating the ApiGateway request. I am unsure of how to acquire the necessary tokens to send with the request so that it is valid, because this is a [serverless-framework] service so I can't use the AWS Console to copy paste the tokens into the request's json data. Moreover, I wouldn't know what json key they'd have to be under anyways. So I guess this question has changed considerably in scope.
I need to respond/delete an active websocket connection established through AWS ApiGatewayV2, in a Lambda. How do I use node js to send a POST
request that ApiGateway can understand?
I saw on the websocket support announcement video that you could issue an HTTP POST
request to respond to a websocket, and DELETE
request to disconnect a websocket. Full table from the video transcribed here:
Connection URL
https://abcdef.execute-api.us-west-1.amazonaws.com/env/@connections/connectionId
Operation Action
POST Sends a message from the Server to connected WS Client
GET Gets the latest connection status of the connected WS Client
DELETE Disconnect the connected client from the WS connection
(this is not documented anywhere else, AFAIK)
Seeing as the AWS SDK does not provide a deleteConnection method on ApiGatewayManagementApi, I need to be able to issue requests directly to the ApiGateway anyways.
const connect = async (event, context) =>
const connection_id = event.requestContext.connectionId;
const host = event.requestContext.domainName;
const path = '/' + event.requestContext.stage + '/@connections/';
const json = JSON.stringify(data: "hello world!");
console.log("send to " + host + path + connection_id + ":n" + json);
await new Promise((resolve, reject) =>
const options =
host: host,
port: '443',
path: path + connection_id,
method: 'POST',
headers:
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(json)
;
const req = https.request(
options,
(res) =>
res.on('data', (data) =>
console.error(data.toString());
);
res.on('end', () =>
console.error("request finished");
resolve();
);
res.on('error', (error) =>
console.error(error, error.stack);
reject();
);
);
req.write(json);
req.end();
);
return success;
;
When I use wscat
to test it out, this code results in the console.log
showing up in CloudWatch:
send to ********.execute-api.us-east-2.amazonaws.com/dev/@connections/*************:
"data": "hello world!"
...
"message": "Missing Authentication Token"
...
request finished
And wscat
says:
connected (press CTRL+C to quit)
>
But does not print hello world!
or similar.
Edit
I was missing
res.on('data', (data) =>
console.error(data.toString());
);
in the response handler, which was breaking things. This still doesnt work, though.
node.js amazon-web-services aws-lambda aws-api-gateway serverless-framework
add a comment |
UPDATE
This issue is partially resolved, the problem now lies in authenticating the ApiGateway request. I am unsure of how to acquire the necessary tokens to send with the request so that it is valid, because this is a [serverless-framework] service so I can't use the AWS Console to copy paste the tokens into the request's json data. Moreover, I wouldn't know what json key they'd have to be under anyways. So I guess this question has changed considerably in scope.
I need to respond/delete an active websocket connection established through AWS ApiGatewayV2, in a Lambda. How do I use node js to send a POST
request that ApiGateway can understand?
I saw on the websocket support announcement video that you could issue an HTTP POST
request to respond to a websocket, and DELETE
request to disconnect a websocket. Full table from the video transcribed here:
Connection URL
https://abcdef.execute-api.us-west-1.amazonaws.com/env/@connections/connectionId
Operation Action
POST Sends a message from the Server to connected WS Client
GET Gets the latest connection status of the connected WS Client
DELETE Disconnect the connected client from the WS connection
(this is not documented anywhere else, AFAIK)
Seeing as the AWS SDK does not provide a deleteConnection method on ApiGatewayManagementApi, I need to be able to issue requests directly to the ApiGateway anyways.
const connect = async (event, context) =>
const connection_id = event.requestContext.connectionId;
const host = event.requestContext.domainName;
const path = '/' + event.requestContext.stage + '/@connections/';
const json = JSON.stringify(data: "hello world!");
console.log("send to " + host + path + connection_id + ":n" + json);
await new Promise((resolve, reject) =>
const options =
host: host,
port: '443',
path: path + connection_id,
method: 'POST',
headers:
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(json)
;
const req = https.request(
options,
(res) =>
res.on('data', (data) =>
console.error(data.toString());
);
res.on('end', () =>
console.error("request finished");
resolve();
);
res.on('error', (error) =>
console.error(error, error.stack);
reject();
);
);
req.write(json);
req.end();
);
return success;
;
When I use wscat
to test it out, this code results in the console.log
showing up in CloudWatch:
send to ********.execute-api.us-east-2.amazonaws.com/dev/@connections/*************:
"data": "hello world!"
...
"message": "Missing Authentication Token"
...
request finished
And wscat
says:
connected (press CTRL+C to quit)
>
But does not print hello world!
or similar.
Edit
I was missing
res.on('data', (data) =>
console.error(data.toString());
);
in the response handler, which was breaking things. This still doesnt work, though.
node.js amazon-web-services aws-lambda aws-api-gateway serverless-framework
what does yourserverless.yml
look like? Do you mind adding it to your question?
– 0x6C38
Jul 9 at 19:21
add a comment |
UPDATE
This issue is partially resolved, the problem now lies in authenticating the ApiGateway request. I am unsure of how to acquire the necessary tokens to send with the request so that it is valid, because this is a [serverless-framework] service so I can't use the AWS Console to copy paste the tokens into the request's json data. Moreover, I wouldn't know what json key they'd have to be under anyways. So I guess this question has changed considerably in scope.
I need to respond/delete an active websocket connection established through AWS ApiGatewayV2, in a Lambda. How do I use node js to send a POST
request that ApiGateway can understand?
I saw on the websocket support announcement video that you could issue an HTTP POST
request to respond to a websocket, and DELETE
request to disconnect a websocket. Full table from the video transcribed here:
Connection URL
https://abcdef.execute-api.us-west-1.amazonaws.com/env/@connections/connectionId
Operation Action
POST Sends a message from the Server to connected WS Client
GET Gets the latest connection status of the connected WS Client
DELETE Disconnect the connected client from the WS connection
(this is not documented anywhere else, AFAIK)
Seeing as the AWS SDK does not provide a deleteConnection method on ApiGatewayManagementApi, I need to be able to issue requests directly to the ApiGateway anyways.
const connect = async (event, context) =>
const connection_id = event.requestContext.connectionId;
const host = event.requestContext.domainName;
const path = '/' + event.requestContext.stage + '/@connections/';
const json = JSON.stringify(data: "hello world!");
console.log("send to " + host + path + connection_id + ":n" + json);
await new Promise((resolve, reject) =>
const options =
host: host,
port: '443',
path: path + connection_id,
method: 'POST',
headers:
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(json)
;
const req = https.request(
options,
(res) =>
res.on('data', (data) =>
console.error(data.toString());
);
res.on('end', () =>
console.error("request finished");
resolve();
);
res.on('error', (error) =>
console.error(error, error.stack);
reject();
);
);
req.write(json);
req.end();
);
return success;
;
When I use wscat
to test it out, this code results in the console.log
showing up in CloudWatch:
send to ********.execute-api.us-east-2.amazonaws.com/dev/@connections/*************:
"data": "hello world!"
...
"message": "Missing Authentication Token"
...
request finished
And wscat
says:
connected (press CTRL+C to quit)
>
But does not print hello world!
or similar.
Edit
I was missing
res.on('data', (data) =>
console.error(data.toString());
);
in the response handler, which was breaking things. This still doesnt work, though.
node.js amazon-web-services aws-lambda aws-api-gateway serverless-framework
UPDATE
This issue is partially resolved, the problem now lies in authenticating the ApiGateway request. I am unsure of how to acquire the necessary tokens to send with the request so that it is valid, because this is a [serverless-framework] service so I can't use the AWS Console to copy paste the tokens into the request's json data. Moreover, I wouldn't know what json key they'd have to be under anyways. So I guess this question has changed considerably in scope.
I need to respond/delete an active websocket connection established through AWS ApiGatewayV2, in a Lambda. How do I use node js to send a POST
request that ApiGateway can understand?
I saw on the websocket support announcement video that you could issue an HTTP POST
request to respond to a websocket, and DELETE
request to disconnect a websocket. Full table from the video transcribed here:
Connection URL
https://abcdef.execute-api.us-west-1.amazonaws.com/env/@connections/connectionId
Operation Action
POST Sends a message from the Server to connected WS Client
GET Gets the latest connection status of the connected WS Client
DELETE Disconnect the connected client from the WS connection
(this is not documented anywhere else, AFAIK)
Seeing as the AWS SDK does not provide a deleteConnection method on ApiGatewayManagementApi, I need to be able to issue requests directly to the ApiGateway anyways.
const connect = async (event, context) =>
const connection_id = event.requestContext.connectionId;
const host = event.requestContext.domainName;
const path = '/' + event.requestContext.stage + '/@connections/';
const json = JSON.stringify(data: "hello world!");
console.log("send to " + host + path + connection_id + ":n" + json);
await new Promise((resolve, reject) =>
const options =
host: host,
port: '443',
path: path + connection_id,
method: 'POST',
headers:
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(json)
;
const req = https.request(
options,
(res) =>
res.on('data', (data) =>
console.error(data.toString());
);
res.on('end', () =>
console.error("request finished");
resolve();
);
res.on('error', (error) =>
console.error(error, error.stack);
reject();
);
);
req.write(json);
req.end();
);
return success;
;
When I use wscat
to test it out, this code results in the console.log
showing up in CloudWatch:
send to ********.execute-api.us-east-2.amazonaws.com/dev/@connections/*************:
"data": "hello world!"
...
"message": "Missing Authentication Token"
...
request finished
And wscat
says:
connected (press CTRL+C to quit)
>
But does not print hello world!
or similar.
Edit
I was missing
res.on('data', (data) =>
console.error(data.toString());
);
in the response handler, which was breaking things. This still doesnt work, though.
node.js amazon-web-services aws-lambda aws-api-gateway serverless-framework
node.js amazon-web-services aws-lambda aws-api-gateway serverless-framework
edited Mar 28 at 8:36
rodolphito
asked Mar 28 at 4:58
rodolphitorodolphito
1604 silver badges9 bronze badges
1604 silver badges9 bronze badges
what does yourserverless.yml
look like? Do you mind adding it to your question?
– 0x6C38
Jul 9 at 19:21
add a comment |
what does yourserverless.yml
look like? Do you mind adding it to your question?
– 0x6C38
Jul 9 at 19:21
what does your
serverless.yml
look like? Do you mind adding it to your question?– 0x6C38
Jul 9 at 19:21
what does your
serverless.yml
look like? Do you mind adding it to your question?– 0x6C38
Jul 9 at 19:21
add a comment |
1 Answer
1
active
oldest
votes
You're likely missing two things here.
- You need to make an IAM signed request to the API Gateway per the documentation located here: Use @connections Commands in Your Backend Service
- You'll need to give this lambda permission to invoke the API Gateway per the documentation here: Use IAM Authorization
I hope this helps!
Thanks for the answer, I've seen this doc page, but it leaves out the most crucial part to a comment:// Do a SigV4 and then make the call
. Maybe I'm missing some obvious way to do it? About the lambda permissions, I think I've got that set up correctly, since I use serverless-framework to do it. (I think its automatic?)
– rodolphito
Mar 28 at 19:04
1
You can use an NPM package like aws4 to generate the sig4 requests.
– Centinul
Mar 28 at 22:49
Thank you so much, thats exactly what I needed!
– rodolphito
Mar 29 at 5:17
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
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%2f55390461%2fmaking-an-https-request-on-aws-apigatewayv2-websocket-connection-to-respond-or%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You're likely missing two things here.
- You need to make an IAM signed request to the API Gateway per the documentation located here: Use @connections Commands in Your Backend Service
- You'll need to give this lambda permission to invoke the API Gateway per the documentation here: Use IAM Authorization
I hope this helps!
Thanks for the answer, I've seen this doc page, but it leaves out the most crucial part to a comment:// Do a SigV4 and then make the call
. Maybe I'm missing some obvious way to do it? About the lambda permissions, I think I've got that set up correctly, since I use serverless-framework to do it. (I think its automatic?)
– rodolphito
Mar 28 at 19:04
1
You can use an NPM package like aws4 to generate the sig4 requests.
– Centinul
Mar 28 at 22:49
Thank you so much, thats exactly what I needed!
– rodolphito
Mar 29 at 5:17
add a comment |
You're likely missing two things here.
- You need to make an IAM signed request to the API Gateway per the documentation located here: Use @connections Commands in Your Backend Service
- You'll need to give this lambda permission to invoke the API Gateway per the documentation here: Use IAM Authorization
I hope this helps!
Thanks for the answer, I've seen this doc page, but it leaves out the most crucial part to a comment:// Do a SigV4 and then make the call
. Maybe I'm missing some obvious way to do it? About the lambda permissions, I think I've got that set up correctly, since I use serverless-framework to do it. (I think its automatic?)
– rodolphito
Mar 28 at 19:04
1
You can use an NPM package like aws4 to generate the sig4 requests.
– Centinul
Mar 28 at 22:49
Thank you so much, thats exactly what I needed!
– rodolphito
Mar 29 at 5:17
add a comment |
You're likely missing two things here.
- You need to make an IAM signed request to the API Gateway per the documentation located here: Use @connections Commands in Your Backend Service
- You'll need to give this lambda permission to invoke the API Gateway per the documentation here: Use IAM Authorization
I hope this helps!
You're likely missing two things here.
- You need to make an IAM signed request to the API Gateway per the documentation located here: Use @connections Commands in Your Backend Service
- You'll need to give this lambda permission to invoke the API Gateway per the documentation here: Use IAM Authorization
I hope this helps!
answered Mar 28 at 18:32
CentinulCentinul
4943 gold badges7 silver badges18 bronze badges
4943 gold badges7 silver badges18 bronze badges
Thanks for the answer, I've seen this doc page, but it leaves out the most crucial part to a comment:// Do a SigV4 and then make the call
. Maybe I'm missing some obvious way to do it? About the lambda permissions, I think I've got that set up correctly, since I use serverless-framework to do it. (I think its automatic?)
– rodolphito
Mar 28 at 19:04
1
You can use an NPM package like aws4 to generate the sig4 requests.
– Centinul
Mar 28 at 22:49
Thank you so much, thats exactly what I needed!
– rodolphito
Mar 29 at 5:17
add a comment |
Thanks for the answer, I've seen this doc page, but it leaves out the most crucial part to a comment:// Do a SigV4 and then make the call
. Maybe I'm missing some obvious way to do it? About the lambda permissions, I think I've got that set up correctly, since I use serverless-framework to do it. (I think its automatic?)
– rodolphito
Mar 28 at 19:04
1
You can use an NPM package like aws4 to generate the sig4 requests.
– Centinul
Mar 28 at 22:49
Thank you so much, thats exactly what I needed!
– rodolphito
Mar 29 at 5:17
Thanks for the answer, I've seen this doc page, but it leaves out the most crucial part to a comment:
// Do a SigV4 and then make the call
. Maybe I'm missing some obvious way to do it? About the lambda permissions, I think I've got that set up correctly, since I use serverless-framework to do it. (I think its automatic?)– rodolphito
Mar 28 at 19:04
Thanks for the answer, I've seen this doc page, but it leaves out the most crucial part to a comment:
// Do a SigV4 and then make the call
. Maybe I'm missing some obvious way to do it? About the lambda permissions, I think I've got that set up correctly, since I use serverless-framework to do it. (I think its automatic?)– rodolphito
Mar 28 at 19:04
1
1
You can use an NPM package like aws4 to generate the sig4 requests.
– Centinul
Mar 28 at 22:49
You can use an NPM package like aws4 to generate the sig4 requests.
– Centinul
Mar 28 at 22:49
Thank you so much, thats exactly what I needed!
– rodolphito
Mar 29 at 5:17
Thank you so much, thats exactly what I needed!
– rodolphito
Mar 29 at 5:17
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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%2f55390461%2fmaking-an-https-request-on-aws-apigatewayv2-websocket-connection-to-respond-or%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
what does your
serverless.yml
look like? Do you mind adding it to your question?– 0x6C38
Jul 9 at 19:21