Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for AWS Lambda in-built UUID
Prabusah
Prabusah

Posted on • Edited on

     

AWS Lambda in-built UUID

Example:

const AWS = require('aws-sdk');exports.handler = async (event) => {   console.log(AWS.util.uuid.v4());}
Enter fullscreen modeExit fullscreen mode

How this works:
Below snippet from aws-sdk-js shows - it does having uuid node dependency included.

  /**   * @api private   */  uuid: {    v4: function uuidV4() {      return require('uuid').v4();    }  }
Enter fullscreen modeExit fullscreen mode

Benefits

  • Avoiding addition of npm dependencyuuid.
  • Reduced code size. Saves few milliseconds of cold start time.

Option: Node.js in-built module crypto

const {randomUUID} = require('crypto'); //Crypto is part of Node.js runtime since v14.17 console.log(randomUUID());
Enter fullscreen modeExit fullscreen mode

Current Node.js lambda runtime 14.x does supports above code.

Learned about this option from@galkin comments to this post. Thank you.

Image byIan Lindsay fromPixabay

Top comments(2)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
galkin profile image
Nikita Galkin
  • Joined

Useconst { randomUUID } = require('crypto');

CollapseExpand
 
fmcdev profile image
fmcdev
  • Joined
• Edited on• Edited

This saved my day with AWS Lambda functions, to replace the AWS.util.uuid.v4() not available anymore in aws-sdk V3 without compiling and adding extra layers!!! Thanks so much!

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Cloud Architect
  • Joined

More fromPrabusah

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp