(ASK) How we debug local websocket with AWS api gateway - node.js

I need to test my functions locally using AWS Web Socket API Gateway. Is there any possible way to mimic or duplicate the behaviour of AWS Web Socket in my local machine ? So I don't need to deploy every little changes to my Lambda function
Thanks

Unfortunately we're still waiting on local sam support for v2 of API Gateway.
https://github.com/awslabs/aws-sam-cli/issues/896

Recently I was able to find here that there is a workaround available called aws-lambda-ws-server which wraps the routes with a websocket server when ran locally and also works deployed as a AWS Lambda.
Hopefully this will help others in the future!

Related

Socket.IO chat not working with load balancer AWS (multiple instances)

I recently integrated basic chat functionality with Socket.IO.
It’s working fine when I am using this with only one instance but while attaching 2 instances to the Application load balancer it just doesn’t work.Message doesn't get received by the user if he is connected on another instance.
Also, I checked for Stickness, & Enabled it but that also doesn't work. What is the recommended way to solve this?
I'm using node.js with express and typescript.

Introducing node.js layer between UI and AWS services

I am designing a solution on AWS that utilizes Cognito for user management.
I am using this Quick Start as a starting point:
SAAS QuickStart
With one significant change: I plan to make this serverless. So no ECS containers to host the services. I will host my UI on S3.
My one question lies with the 'auth-manager' used in the existing solution, and found on github:
Auth-Manager using Node.js
Basically, this layer is used by the UI to facilitate interaction with Cognito. However, I don't see an advantage to doing it this way vs. simply moving these Cognito calls into the front-end web application. Am I missing something? I know that such a Node layer may be advantageous for providing a caching layer but I think I could just utilize Elasticache(Redis)as a service if I needed that.
Am I missing something? If I simply moved this Node auth-manager piece into my S3 static Javascript application, am I losing something?
Thanks in advance.
It looks like its pulling some info from
https://github.com/aws-quickstart/saas-identity-cognito/blob/master/app/source/shared-modules/config-helper/config.js
//Configure Environment
const configModule = require('../shared-modules/config-helper/config.js');
var configuration = configModule.configure(process.env.NODE_ENV);
which exposes lots of backend AWS account info, which you wouldn't want in a front end app.
Best case seems to run this app on a small ec2 instance instead of faragte because of the massive cost difference, and have your front-end send requests for authorization.

How to integrate a database to api.ai chat-bot using a webhook

I'm developing a chat-bot using api.ai for NLP and i'm stucked where i need to query some data from a database. And also i need to do some processing of those data. I'm not much clear how can I do this using the webhook. Any thoughts and tips would be really appreciated.
You might want to check out API.AI's getting started guide, the last part of which involves the basics of adding fulfillment to your agent which pulls from this getting started sample
We use Cloud Functions for Firebase in the sample but you can't call non-Google APIs or URLs without setting up billing. You can also use any other hosting providers (Google's AppEngine, Compute Engine, Amazon's Lambda, EC2, Heroku, Azure, etc.) for fulfilling API.AI agents, as long as you have a server that can respond to a HTTPS request, it'll work with API.AI's webhook fulfillment. To get started you can even use your local machine and tools like ngrok to tunnel the connection from a HTTPS URL to your local development machine: https://ngrok.com/. If your just starting out I'd recommend doing whatever your most comfortable with.
Am currently using Node-RED to process the data received through the webhook. The webhook receives the data in JSON and if you’ve setup your intents and entities correctly, you’ll get data that you can act on.
This can be achieved as a stand-alone nodeJS app that you host somewhere, like Heroku or OpenShift. But important point is that you need a server running a program somewhere to process the data that api.ai sends.
Am using firebase as my database and is integrated into my Node-RED setup and now I can do sophisticated queries like “how much did I walk last Wednesday”

How to use Socket.io in aws lambda functions

I'm using node js with aws lambda functions for my web application. I want to use web socket in my web app. And socket.io is a very famous library for node.js.
But I'm not sure how can I use it in aws lambda. can anyone let me know how to do it, is it possible using lambda functions?
Can't use socket.io with lambdas. Lambdas have a limit on time it can be executed, so holding open connection with a client is impossible.
What you can do though is use SNS. Lambdas can publish messages to SNS topics and lambdas can be invoked with SNS.
Workaround exists for this - it's the WebSockets over MQTT in AWS IoT. This way you can execute your Lambda functions from open socket connections.
Currently, AWS API Gateway supports WebSockets.
Unfortunately, I didn't manage to connect via socket.io since it generates a custom URL with additional params: /?EIO=3&transport=polling&sid=< id>
But I've found tiny WebSocket wrapper sockette (used this tutorial), and it works fine!

AWS Lambda blocking all outgoing URL calls

Basically the above problem. I see no error in the logs, however when I check the script on a seperate server it just works fine. I'm doing an API call to Watson and a simple (get) call to an IFTTT Maker link. I write in Node.js and use the request module.
Is AWS Lambda blocking the connection of HTTPS URL's and if so, what can I do to surpass this unfortunate event? I've already seen a similar issue on another thread which was solved using the request module, but sadly this doesn't work for me.
Any help would be much appreciated.
Maybe your Lambda function lives in a private subnet, inside a VPC?
If yes, then it does not have internet access, which means all calls to public servers will time out (see the docs).
In that case, you've got 2 options:
Do not launch your Lambda function inside a VPC.
Allow your private subnet to access the internet by setting up a NAT Gateway. Example guide here.

Resources