I am trying to deploy the Webhook Example for Google Actions found here onto Lambda AWS.
I was successful deploying and making the POST calls using ngrok. So, no problems there.
But the issue i found is it uses Express node module for POST request calls. Lambda AWS fails when the request is made to Express module. So is there a way to make the POST call successful.
I tried using Lambda-Express node module to deploy it, but it seems to have some issue as well.
Lambda AWS does not directly support an HTTP interface.
One solution would be for you to use API Gateway which would allow you to translate the HTTPS POST that AoG sends, into a call to AWS Lambda.
In your lambda you will handle the request which comes in via the standard Lambda handler:
function( event, context, callback );
instead of via Express. You would probably also want to remove Express from your code, which might sound like a lot of work, but I took a brief look at it when it was released and my impression was that the dependence on Express was minor and quite unnecessary.
The alternative would be to switch from Lambda to something HTTP based like Google App Engine which is also serverless (to a degree). I guess that might be easier but I don't know what your other factors might be.
I have come across this tutorial that explains the step by step process of connecting API.ai intent using the Lambda function.
And if you follow the Google web hook example to deploy it to Lambda, then it's a wrong direction. Completely eliminate the express usage and also the Assistant class is not necessary when Lambda deployment is necessary.
Related
I have 5 HTTP microservices written with NestJS. I have to convert them into lambda function where each service will have its own lambda function. The purpose of this is to completely turn my service to serverless.
I am using API Gateway to map requests to the right lambda by the given request path.
Now creating an MVC pattern from scratch that receives an URL path and resolves and controller & function needed (including url params, and such) is something that has already been done by both express and nestjs.
Is there a way to implement nesstjs's abstraction functionality without the actual server listening? So I can simply pass nestjs the URI and request data and it will work upon it?
Any other solutions for running an MVC serverless process on lambda?
After researching the network and looking at these great answers, I thought of collecting that information all together and bring something more detailed, things that I was misunderstanding from these articles described and the ones I found.
How to create a serverless NestJS application using Lambda function AWS provider
Let's take a look at this repository article: https://github.com/rdlabo/serverless-nestjs
Thanks to him, he basically packed a ready-to-go NestJS project configured with the Serverless framework.
I am not experienced enough to say a lot about the serverless framework, but I can explain how it works in our case.
First of all, there is a serverless.yml as explained the the github repository article, basically here you describe the name of your lambda function, what to exclude in the package and the trigger http events.
functions:
index:
handler: dist/index.handler
events:
- http:
cors: true
path: '/'
method: any
- http:
cors: true
path: '{proxy+}'
method: any
If we take a look at this yml file, you can see that we have 2 HTTP events, one for root path and one for proxy path.
A question that I asked myself when reading through it, so what does this event part do?
This part of the yml basically creates your endpoints in the API Gateway service of AWS (if you are using AWS as a provider).
API Gateway is a service made by AWS that lets you map requests into other services of AWS, such as a lambda function.
When you run the command sls deploy
after entering your credentials using sls config credentials the serverless framework will create OR modify if exists a new lambda function based on the config you set up, and set up API Gateway endpoints linked to that lambda.
After deploying you will receive a link that activates that lambda.
The example I use basically uses an express serverless solution that someone created, basically a proxy code that knows how to receive API Gateway request object and transform it to express and activate it without having a server running.
Note: Serverless is using CloudFormation to create a stack in order to upload and deploy the lambda function, I think with this way you can upload more than 250mb unzipped, because my project currently is 450mb unzipped, I am not sure about this but when I tried uploading a bigger zip, my lambda started overflowing, as in saying that it is missing some modules, I guess because of the size.
Or maybe serverless really optimizes the modules so the uploaded package is much smaller than what you expect. If someone knows about this, +1!
You must provide more info about your architecture.
Have you used Blueprint with microservice?
Then choose microservice-http-endpoint.
Take a look at [microservice-http-endpoint] example.
1
You can convert you whole express app in a lambda function and process request as they come in.
This blog shows how to do it for express: https://serverless.com/blog/serverless-express-rest-api/
Similar thing can be tried for NestJS as well. So lambda function is basically a piece of code that gets executed as the request come in. There are limitation on the size of the code and time to execute a job which is platform specific.
I have an API that is secured using OAuth (IdentityServer 4). I need to call this from an AWS Lambda function. I cant figure out how to do this in Node (noob to node). I can see an example of using oidc-client package but it seems to be designed for browser based clients. I just need the access token to call the api. Ive done this from a .Net console app, but Im lost in Node. Does anyone know of an example of doing this?
Thanks
#Jonesie have you tried example from AWS repository? Request you to take a look https://github.com/awslabs/serverless-application-model/tree/master/examples/apps/api-gateway-authorizer-nodejs
I am totally new to Lambda (or AWS) and am still to build knowledge and experience around it.
Now, I was building an app where in it requires to fetch data from twitter Hashtag.
If I got it correctly, Twitter restricts number of API calls we make every minute(?) hence we need to have a backend and needs to have oAuth2 authentication.
In a simple express app, I would have done an API call in the global scope to get the data and use setInterval to hit that API after every x minute so as to not exceed number of limits.
Now based on the very vague understanding, I guess Lambda runs function when we need it, Hence is it right to assume that we can't use lambda for such use cases?
The old-school way of doing this is to run a cron job that fires a particular script every so often. The AWS way of running code periodically is using CloudWatch scheduled events. You can configure how often you want to run a given target, and set the target as a lambda function.
https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/RunLambdaSchedule.html
Im building a web app in hapi.js. Im pretty new to hapi.js so may not be following the framework correctly. But here is what I intend to do.
Create a hapi route which will use one of the route params to make a series of web service calls to an external host. These calls need to be done in series.
I am currently using axios to make the calls and chaining them with
.then().then() etc.
I would like to cache these responses to a redis store. I read up on the hapi caching examples of using catbox and hapi "server.methods" feature but not sure how they could be applied to a promise based call chain that I have currently. Is there something wrong with my thinking.
Catbox the caching module used by hapi does not support promises as stated here, maybe open an issue on Github or ask a question on gitter or on Github user forum to see what other users are doing.
Which is the best way of making call to AWS services like S3,Dynamodb,cloudwatch etc from parse cloud code (offcourse while taking care of cloud function timeouts)?
Importing AWS sdk in parse cloud code is showing lot of wierd errors relating to internal file dependencies which is very time consuming to resolve.
Is calling them via aws lambda function REST call advisable? or Please quote me an example if some better technique is available.
Thanks