How AWS lambda supports different versions of NodeJS - node.js

Recently AWS released the processing service, lambda. It can be triggered in milliseconds and only supports NodeJS now.
I'm curious about how can they implement the resource isolation. If they use something like docker, it may take a few seconds to start a container. If they run the NodeJS code directly, how can they support different version of NodeJS? It will be the big problem if you want to support other programming languages.

According to the docs, Lambda currently (at the time of this writing) supports only v0.10.32. In the future they will likely have an option when creating the cloud function specify the language and version. Lambda will ensure it runs in the correct execution environment (which, by the way, is probably not Docker).

Related

How do I run puppeteer on a server/in the cloud

Feels like I've searched the entire web for an answer...to no avail. I have a puppeteer script that works perfectly locally. My local machine is a little unreliable, so I've been trying to push this script to the cloud so that it can run there. But I have no idea where to start. I'm sitting here with an IBM cloud account with no idea what to do. Can anyone help me out?
Running Puppeteer scripts can be done on any cloud platform that
exposes a Node.js environment
enables running a browser (Puppeteer will need to start Chromium)
This could be achieved, for example, using AWS EC2.
AWS Lambda, Google Cloud Functions and IBM Cloud Functions (and similar services) might also work but they might need additional work on your side to get the browser running.
For a step-by-step guide, I would suggest checking out this article and this follow-up.
Also, it might just be easier to look into services like Checkly (disclaimer: I work for Checkly), Browserless and similar (a quick search for something along the lines of "run puppeteer online" will return several of those), which allow you to run Puppeteer checks online without requiring any additional setup. Useful if you are serious about using Puppeteer for testing or synthetic monitoring in the long run.

Can aws-sdk be a development dependency when developing lambdas with NodeJS?

I am quite new in trying to develop lambdas with NodeJs, so this question might sound silly.
One of the limitations of lambdas is the size of the function / dependencies (250 MB) and I was wondering if aws-sdk (which has >45 MB)can be treated as a dev-dependency since it occupies 1/5 of the total size of a lambda.
I understand that this is required during development, but is it not the case that this already exists in the lambda container once deployed to AWS?
Any suggestion would help as all the articles that I browsed seem to install it as a prod dependency.
Absolutely, the aws-sdk is available by default as an NPM dependency inside of the lambda containers so if you leave it as a development dependency your code will still work inside of lambda.
Here you can see which lambda containers contain which version of the AWS SDK. So in case you really need a specific version or one that's not yet loaded onto the lambda containers, you can manually include your own.

AWS - Steps/Consideration for migrating to latest generation of ec2 from an older generation

I am looking at upgrading from older generation ec2 to the latest generation for example m3.medium to m5.large. Are there any steps or considerations that need to be made when making this change? I couldn't find any documentation that is linux specific, only windows specific: https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/migrating-latest-types.html.
If anybody could help me I would really appreciate it.
To upgrade the instance type on AWS I usually follow this official doc
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-resize.html
However it also depends on the complexity of application running on your instance viz. just an apache server or a database? To handle that situation as #Marcin mentioned, always start with AMI of your instance and try doing any change before applying directly on production instances.
screenshot from the official doc

How is it possible to debug an AWS Lambda function from remote?

We are taking over a whole application from another company, and they have built the whole pipeline for deploying, but we still don't have access to it. What we know, that there's a lambda function is running triggered by certain SNS messages, and all the code is in Node.js, and the development is in VS Code. We also have issues debugging it locally, but it's a bigger problem, that we need to debug it remotely.
Since I am new in AWS services, I'd really appreciate if somebody could help me in this.
Does it necessary to open a port? How is it possible to connect to a lambda? Do we need serverless to setup? Many unresolved questions.
I don't think there is way you can debug a lambda function remotely. Your best bet is to download the code on local machine, setup the env variables as you have set up on your lambda function and take it from there.
Remember at the end of the day lambda is just a container which is running the code for you. AWS doesn't allow any ssh or connection with those container. In your case you should be able to debug it on local till you have the same env variables. There are other things as well which are lambda specific but considering it is a running code which you have got so you should be able to find out the issue.
Hope it makes sense.
Thundra (https://www.thundra.io/aws-lambda-debugger) has live/remote debugging support for AWS Lambda through its native IDE plugins (VSCode and IntelliJ IDEA).
The way AWS have you 'remote' debug is to execute the lambda locally through Docker as it proxies the requests to the cloud for you, using AWS Toolkit. You have a lambda running on your local computer via docker that can access resources on the cloud, such as databases, api's etc. You can step through debug them using editors like vscode.
I use SAM with a template.yaml . This way, I can pass event data to the handler, reference dependency layers (shared code libraries) and have a deployment manifest to create a Cloudformation stack (release instance with history and resource management).
Debugging can be a bit slow as it compiles, deploys to Docker and invokes, but allows step through debugging and variable inspection.
https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-using-debugging.html
While far from ideal, any console-printing actions would likely get logged to CloudWatch, which you could then access to go through printed data.
For local debugging, there are many Github projects with Dockerfiles which which you can build a docker container locally, just like AWS does when your Lambda is invoked.

How to create a mirror environment of lambda AWS

I have had a bunch of issues with few lambda functions in AWS. I would like to simulate the lambda environment in order to troubleshoot better what's wrong with my scripts. Unfortunately, the gotten errors in the logs are not too much useful. I have posted few of them here.
I would like to know then, how could I simulate in a docker image or even in an AMI the exact environment as my lambda function is running to catch more details on my error. What would you suggest me?
thanks so much
There are a number of ways to run and debug Lambda functions locally. I'm not sure any of them are 100% representative of the actual Lambda environment, however.
SAM Local is one option provided by AWS, and is built on top of Serverless Application Model (SAM). Other options include Cloud9, emulambda.
If your issues are timeouts then you should be able to detect where the delays are simply by adding more logging and review the resulting CloudWatch Logs. If the cause is high network latency for a given API request or SQL query then investigate the other end to determine why it responds slowly.
You can try to use python-lambda-local package or use SAM Local (it's still in Beta).

Resources