AWS Lambda, no longer provides default access to aws-sdk? [duplicate] - node.js

I upgraded my Lambda function from node12.x to node18.x
The code worked perfectly fine on 12.x, after switching to 18.x, I can no longer include the AWS sdk:
I used to include it by simply typing:
var AWS = require('aws-sdk');
I now get this error
"Error: Cannot find module 'aws-sdk'
I think if I can just get the AWS sdk to load properly the function should be fine, any ideas?
Thanks

The Node.js 18 Lambda runtime is preloaded with the AWS SDK for JS v3.
The earlier runtimes have the SDK v2.
Of course you can still use the SDK v2 with the Node.js 18 runtime. You just need to package the clients as dependencies with your Lambda code.

Related

How do I get exact version numbers of NodeJS my AWS lambda currently supports?

How do I get the exact versions of Node.js, e.g. 18.1.2 that I can run on AWS lambda? The documentation gives me 18.x which is not very specific.
Seems like:
AWS doesn't show node.js version in the UI, so you need to console.log(process.version)
the version can change at any time, no one will notify you

Amazon AWS S3 autoDeleteObjects lambda

Could you please help me understand how to specify the nodejs runtime version of the lambda function that gets automatically created by aws when a new data bucket with parameter
autoDeleteObjects: true is created?
I am using the following piece of code:
const autoDeleteBucketProps = { autoDeleteObjects: true, removalPolicy: >cdk.RemovalPolicy.DESTROY };
new Bucket(this, 'store', {
...bucketProps,
...autoDeleteBucketProps
});
This code automatically creates a lambda function with runtime version Node.js 12.x for autodeleting objects. However due to the fact that Amazon requires that we upgrade our lambda runtimes (ending support of v12 as described in Lambda runtime support policy), I am trying to a find a way to upgrade the runtime of this automatically created lambda to version 14.
I am using aws-cdk v1.152.0 which supports '#aws-cdk/aws-lambda' Runtime version v14. So why this lambda gets created with runtime v12? And how can it can be changed to v14, programmatically?
Thank you in advance.
I just updated one of our stacks from CDK 2.23.0 to 2.46.0 and the auto deletion lambda automatically updated to Node 14 runtime.
You said you were using CDK 1.152.0 and if for some reason you want to stick with V1, it should also update to the new runtime in 1.176.0, but I have not tested this myself. I was just reading the changelog notes of CDK.
Updating to CDK v2 was quite easy for us at least and I think v1 is nearing end-of-life so I suggest you move to v2 now or soon.
I think you should be able to update the runtime in the console or remake the function when v12 is no longer used.
You can find more details on the lambda runtimes here

AWS CloudFormation with node.js 10.x Update Error "ZipFile can only be used when Runtime is set to <older node.js versions>"

We are using CloudFormation template to deploy some intermediate code on Lambda function.
We are using ZipFile function to add inline code through CloudFormation.
Current runtime for lambda function is node.js 8.10.
We need to update node version to 10.x.
While updating Lambda using cloudformation we are getting below error:
ZipFile can only be used when Runtime is set to either of nodejs,
nodejs4.3, nodejs6.10, nodejs8.10, python2.7, python3.6, python3.7.
I believe that this is a known issue. https://forums.aws.amazon.com/thread.jspa?threadID=303166&tstart=0
As of this writing, it is still an issue. My suggestion is to have super basic code in an S3 bucket and reference that instead of using a zip file and deploy your actually code after the lambda function is created. Alternatively, you can just upload your zip artifact to an S3 bucket. If your code is proprietary be careful about S3.

AWS Lambda to Firestore error: cannot import name 'cygrpc'

On my AWS Lambda Python 3.6 function I'd like to use Google Firestore (Cloud Firestore BETA) for caching purposes, but as soon as I add
from google.cloud import firestore
to my Python script and upload ZIP to AWS Lambda function, Lambda test come back with error
Unable to import module 'MyLambdaFunction': cannot import name 'cygrpc'.
AWS CloudWatch log doesn't contain any details on the error, just that same error message.
Lambda function works great on my local dev machine (Windows 10), and I can write to Firestore fine. It also works on AWS if I comment out the import and all Firestore related lines.
Any tips how I could go about solving this?
The python client for Firestore relies on the C-based implementation of GRPC. This appears not to work by default in AWS Lambda.
Node.js users have reported similar problems and they've documented a workaround of building a docker image.
This should be similar to any getting any other python package that requires native code to work. Perhaps something like this method for getting scikit to work?
I hope this is enough to get you going in the right direction, but unfortunately I don't know anything about AWS Lambda :-(.
Ran into same issue, i solved it by using the plugin serverless-python-requirements for serverless framework and passing:
pythonRequirements:
dockerizePip: true
Essentially this installs your c-based packages (and all other packages) in a docker container where it would work and then symlinks them to your lambda fn.
A helpful guide can be found on: https://serverless.com/blog/serverless-python-packaging/
Plugin: https://github.com/UnitedIncome/serverless-python-requirements

CRUD operations to couchbase from AWS Lambda using couchbase sdk for node.js

I need to run CRUD operations on my bucket (database) in couchbase which is deployed ec2 instance. And the code which I have is running on aws lambda. However, when I try to test this code on lambda by passing details in the body I get the error as : "errorMessage": "/usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by /var/task/node_modules/couchbase/build/Release/couchbase_impl.node)". This error is because in my function I require an npm module called "couchbase" which is used for executing CRUD operations on my couchbase bucket.
So can you guys help me as to what might be the problem here? Is the file missing on nodejs environment running on lambda or do I need to implement in a different way so as to get it working?
Thanks in advance.
I was able to solve this issue by locally compiling node_modules with the same nodejs version (v0.10.36) which lambda uses and uploading the zip file to lambda.

Resources