I am receiving this Error when trying to use UUID Module in AWS Lambda JavaScript code.
Error: Cannot find module 'uuid/v4'
I am not using AWSCLI or NPM, i am instead using the AWS Lambda dashboard to author the Lambda Functions in JavaScript.
const AWS = require('aws-sdk');
const AWSUUID = require('uuid/v4');
const AWSGamelift = new AWS.GameLift();
exports.handler = async (event) =>
{
//...
Ive been searching Google nonstop trying to find a way to get the UUID Module to work. I do not want to have to setup and use an NPM environment.
Is there some method on the AWS Lambda dashboard to provide access to the UUID Module for Lambda code?
You need to install uuid package. uuid recently did a breaking change, the way you use it. New way is
const {"v4": uuidv4} = require('uuid');
Hope this helps.
AWS Lambda Layers is an option for this if we don't want to set up any npm environment.
Create a new layer for your Lambda function from the AWS console and upload the zip file from the node_modules directory that contains the uuid npm package.
A few things to remember to get this working:
This is important, otherwise the Lambda function will not recognize the packages.
lambda:GetLayerVersion action permission, otherwise you'll run into a problem with the missing package. This is clearly explained in the documentation mentioned above.Once done, you can run your code. response example
The nodejs folder structure is as follows
navigate to that file, and look around line number 3 in node_modules/expo-constants/exponentConstants.web.js
import uuidv4 from 'uuid/v4
and change it to:
import {v4 as uuidv4} from 'uuid';
This error happens because of the file structure in node_modules/uuid, if you look there is no longer a uuidv4 to import and instead they export a v4. You could change all the places where the developers wrote uuidv4 to v4 but using the { this as that } syntax you don't have to rewrite a bunch of code.