{"id":97046,"date":"2024-08-08T10:24:36","date_gmt":"2024-08-08T04:54:36","guid":{"rendered":"https:\/\/www.whizlabs.com\/blog\/?p=97046"},"modified":"2024-08-08T11:49:49","modified_gmt":"2024-08-08T06:19:49","slug":"aws-sdk-integration-node-js","status":"publish","type":"post","link":"https:\/\/www.whizlabs.com\/blog\/aws-sdk-integration-node-js\/","title":{"rendered":"Mastering AWS SDK Integration in Node.js: A Step-by-Step Guide"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">Integrating AWS SDKs into your Node.js application opens up a world of possibilities, allowing you to leverage the power and scalability of AWS services directly from your code. Whether you are creating serverless functions, deploying applications on EC2, or managing resources with Elastic Beanstalk, understanding how to set up and use AWS SDKs is crucial.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0For those aiming to become an <\/span><a href=\"https:\/\/www.whizlabs.com\/aws-developer-associate\/\" target=\"_blank\" rel=\"nofollow noopener\"><span style=\"font-weight: 400;\">AWS Certified Developer Associate<\/span><\/a><span style=\"font-weight: 400;\">, mastering these skills is essential. In this guide, we will walk you through the process of setting up an AWS Node.js environment, installing necessary SDKs and dependencies, configuring credentials securely, and writing and running your first Node.js application that interacts with AWS services.<\/span><\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_76 ez-toc-wrap-left counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #ea7e02;color:#ea7e02\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #ea7e02;color:#ea7e02\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.whizlabs.com\/blog\/aws-sdk-integration-node-js\/#How_to_Set_Up_and_Integrate_AWS_SDKs_into_Your_Nodejs_Environment\" >How to Set Up and Integrate AWS SDKs into Your Node.js Environment?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.whizlabs.com\/blog\/aws-sdk-integration-node-js\/#Prerequisites\" >Prerequisites<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.whizlabs.com\/blog\/aws-sdk-integration-node-js\/#Installation_of_SDK_and_Dependencies\" >Installation of SDK and Dependencies<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.whizlabs.com\/blog\/aws-sdk-integration-node-js\/#Configuring_Credentials\" >Configuring Credentials<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.whizlabs.com\/blog\/aws-sdk-integration-node-js\/#Creating_the_Projects_Package_JSON\" >Creating the Projects\u2019 Package JSON<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.whizlabs.com\/blog\/aws-sdk-integration-node-js\/#Writing_the_Nodejs_Code\" >Writing the Node.js Code<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.whizlabs.com\/blog\/aws-sdk-integration-node-js\/#_Verifying_Versions_of_TLS\" >\u00a0Verifying Versions of TLS<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.whizlabs.com\/blog\/aws-sdk-integration-node-js\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"How_to_Set_Up_and_Integrate_AWS_SDKs_into_Your_Nodejs_Environment\"><\/span><span style=\"font-weight: 400;\">How to Set Up and Integrate AWS SDKs into Your Node.js Environment?<\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">To integrate AWS SDKs, you need to set an AWS Node.js environment so that you will be able to run your application. The following options can be considered:<\/span><\/p>\n<p><b>Option 1:<\/b><span style=\"font-weight: 400;\"> Choosing an Amazon Machine Image (AMI) that has already been pre-installed with Node.js to create an Amazon EC2 instance. Search the AWS marketplace for an AMI option with 32-bit or 64-bit versions of Node.js. This option leverages IAM roles for <\/span><a href=\"https:\/\/www.whizlabs.com\/blog\/amazon-elastic-compute-cloud-guide\/\" target=\"_blank\" rel=\"nofollow noopener\"><span style=\"font-weight: 400;\">Amazon EC2<\/span><\/a><span style=\"font-weight: 400;\"> which provides credentials automatically to the instance. This eliminates the need to provide credentials manually.<\/span><\/p>\n<p><b>Option 2:<\/b><span style=\"font-weight: 400;\"> Installing Node.js on an <\/span><b>Amazon EC2<\/b><span style=\"font-weight: 400;\">.<\/span><\/p>\n<p><b>Option 3:<\/b><span style=\"font-weight: 400;\"> Running Node.js as a Lambda function on a serverless environment created through AWS Lambda.\u00a0 This creates a unique IAM role with permission to execute functions. You must specify the<\/span><a href=\"https:\/\/www.whizlabs.com\/blog\/iam-roles-for-aws-lambda-function\/\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\"> IAM role<\/span><\/a><span style=\"font-weight: 400;\"> when setting up a Lambda function. See the tutorial to be guided<\/span><\/p>\n<p><b>Option 4:<\/b><span style=\"font-weight: 400;\"> Use Elastic Beanstalk to deploy your Node.js. See<\/span><a href=\"https:\/\/docs.aws.amazon.com\/elasticbeanstalk\/latest\/dg\/create_deploy_nodejs.html\" target=\"_blank\" rel=\"nofollow noopener\"> <span style=\"font-weight: 400;\">AWS Elastic Beanstalk<\/span><\/a><span style=\"font-weight: 400;\"> to learn more.<\/span><\/p>\n<p><b>Option 5:<\/b><span style=\"font-weight: 400;\"> Creating a Node.js application server through<\/span><a href=\"https:\/\/docs.aws.amazon.com\/opsworks\/latest\/userguide\/gettingstarted-node.html\" target=\"_blank\" rel=\"nofollow noopener\"> <span style=\"font-weight: 400;\">AWS OpsWorks<\/span><\/a><span style=\"font-weight: 400;\">.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Setting Up an AWS Node.js Environment is supported by the following browsers and their versions.<img decoding=\"async\" class=\"alignnone wp-image-97054 size-large\" src=\"https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2024\/08\/AWS-SDKs-info-1024x417.webp\" alt=\"AWS Node.js Versions\" width=\"1024\" height=\"417\" srcset=\"https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2024\/08\/AWS-SDKs-info-1024x417.webp 1024w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2024\/08\/AWS-SDKs-info-300x122.webp 300w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2024\/08\/AWS-SDKs-info-768x313.webp 768w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2024\/08\/AWS-SDKs-info-1536x626.webp 1536w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2024\/08\/AWS-SDKs-info-2048x834.webp 2048w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2024\/08\/AWS-SDKs-info-150x61.webp 150w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Prerequisites\"><\/span><span style=\"font-weight: 400;\">Prerequisites<\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">You need to create a working directory for your Node.js and save it on a location that be updated. Avoid the \u201cC:\\Program Files\u201d. Name your directory as <\/span><b>awsnodesample<\/b><span style=\"font-weight: 400;\">. Now visit the<\/span><a href=\"https:\/\/nodejs.org\/\" target=\"_blank\" rel=\"nofollow noopener\"> <span style=\"font-weight: 400;\">Node.js website<\/span><\/a><span style=\"font-weight: 400;\"> to download and install current and LTS version of Node.js.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Note that Amazon S3 bucket names are normally required to be unique globally and for this example we have used a third-party Node.js to achieve this. This module is known as <\/span><b>uuid.<\/b><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Installation_of_SDK_and_Dependencies\"><\/span><span style=\"font-weight: 400;\">Installation of SDK and Dependencies<\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">The first step you need to take is to install the SDK for the JavaScript package. This is done\u00a0 using<\/span><a href=\"https:\/\/www.npmjs.com\/\" target=\"_blank\" rel=\"nofollow noopener\"> <span style=\"font-weight: 400;\">Node.js Package Manager (NPM)<\/span><\/a><span style=\"font-weight: 400;\">. From your package directory of <\/span><b>awsnodesample<\/b><span style=\"font-weight: 400;\">, insert these command lines.<\/span><\/p>\n<p><b>npm install aws-sdk<\/b><\/p>\n<p><span style=\"font-weight: 400;\">Your <\/span><b>package. Json <\/b><span style=\"font-weight: 400;\">directory will be updated to list the project dependency once the command installs SDK for JavaScript. You can visit the<\/span><a href=\"https:\/\/www.npmjs.com\/\" target=\"_blank\" rel=\"nofollow noopener\"> <span style=\"font-weight: 400;\">npm website<\/span><\/a><span style=\"font-weight: 400;\"> and search \u201caws-sdk\u201d to obtain more information on the package.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Now enter this command line:<\/span><\/p>\n<p><b>npm install uuid<\/b><\/p>\n<p><span style=\"font-weight: 400;\">The <\/span><b>uuid<\/b><span style=\"font-weight: 400;\"> module will be installed on the project and <\/span><b>package. json<\/b><span style=\"font-weight: 400;\"> will be updated.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">For more information, see<\/span><a href=\"https:\/\/docs.aws.amazon.com\/sdk-for-javascript\/v2\/developer-guide\/installing-jssdk.html\" target=\"_blank\" rel=\"nofollow noopener\"> <span style=\"font-weight: 400;\">Installing the SDK for JavaScript<\/span><\/a><span style=\"font-weight: 400;\">.<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Configuring_Credentials\"><\/span><span style=\"font-weight: 400;\">Configuring Credentials<\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">For you to access your account and its resources privately, you will need to configure credentials. It is recommended that you create a shared credential file. See<\/span><a href=\"https:\/\/docs.aws.amazon.com\/sdk-for-javascript\/v2\/developer-guide\/loading-node-credentials-shared.html\" target=\"_blank\" rel=\"nofollow noopener\"> <span style=\"font-weight: 400;\">Credential in Node.js<\/span><\/a><span style=\"font-weight: 400;\"> to learn how. Your file should look like this:<\/span><\/p>\n<p><b>[default]<\/b><\/p>\n<p><strong>aws_access_key_id = YOUR_ACCESS_KEY_ID<\/strong><\/p>\n<p><strong>aws_secret_access_key = YOUR_SECRET_ACCESS_KEY<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0<\/span><span style=\"font-weight: 400;\">It is important that you confirm you have set the right credentials. Execute the following code on Node.js to confirm:<\/span><\/p>\n<p><b>var AWS = require(&#8220;aws-sdk&#8221;);<\/b><\/p>\n<p><b>AWS.config.getCredentials(function(err) {<\/b><\/p>\n<p><b>\u00a0\u00a0if (err) console.log(err.stack);<\/b><\/p>\n<p><b>\u00a0\u00a0\/\/ credentials not loaded<\/b><\/p>\n<p><b>\u00a0\u00a0else {<\/b><\/p>\n<p><b>\u00a0\u00a0\u00a0\u00a0console.log(&#8220;Access key:&#8221;, AWS.config.credentials.accessKeyId);<\/b><\/p>\n<p><b>\u00a0\u00a0}<\/b><\/p>\n<p><b>});<\/b><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0<\/span><span style=\"font-weight: 400;\">To display the value set in your configuration file, run this code:<\/span><\/p>\n<p><b>var AWS = require(&#8220;aws-sdk&#8221;);<\/b><\/p>\n<p><b>console.log(&#8220;Region: &#8220;, AWS.config.region);<\/b><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Creating_the_Projects_Package_JSON\"><\/span><span style=\"font-weight: 400;\">Creating the Projects\u2019 Package JSON<\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">To hold the metadata of your Node.js project, you need to add a package<\/span><b>. json<\/b><span style=\"font-weight: 400;\"> to your <\/span><b>awsnodesample<\/b><span style=\"font-weight: 400;\"> project directory. Go to your project directory and create a new file <\/span><b>package. json<\/b><span style=\"font-weight: 400;\"> and add the following:<\/span><\/p>\n<p><b>{<\/b><\/p>\n<p><b>\u00a0\u00a0&#8220;dependencies&#8221;: {},<\/b><\/p>\n<p><b>\u00a0\u00a0&#8220;name&#8221;: &#8220;aws-nodejs-sample&#8221;,<\/b><\/p>\n<p><b>\u00a0\u00a0&#8220;description&#8221;: &#8220;A simple Node.js application illustrating usage of the SDK for JavaScript.&#8221;,<\/b><\/p>\n<p><b>\u00a0\u00a0&#8220;version&#8221;: &#8220;1.0.1&#8221;,<\/b><\/p>\n<p><b>\u00a0\u00a0&#8220;main&#8221;: &#8220;sample.js&#8221;,<\/b><\/p>\n<p><b>\u00a0\u00a0&#8220;devDependencies&#8221;: {},<\/b><\/p>\n<p><b>\u00a0\u00a0&#8220;scripts&#8221;: {<\/b><\/p>\n<p><b>\u00a0\u00a0\u00a0\u00a0&#8220;test&#8221;: &#8220;echo \\&#8221;Error: no test specified\\&#8221; &amp;&amp; exit 1&#8243;<\/b><\/p>\n<p><b>\u00a0\u00a0},<\/b><\/p>\n<p><b>\u00a0\u00a0&#8220;author&#8221;: &#8220;NAME&#8221;,<\/b><\/p>\n<p><b>\u00a0\u00a0&#8220;license&#8221;: &#8220;ISC&#8221;<\/b><\/p>\n<p><b>}<\/b><\/p>\n<p><span style=\"font-weight: 400;\">Now save the file and the <\/span><b>dependencies <\/b><span style=\"font-weight: 400;\">portion of the file will be completed.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">It is important to note that when configuring credentials in Node.js, you have to be careful not to over rely on more than one source of the JSON file you are loading. To supply your credential in order of recommendation, follow these steps:<\/span><\/p>\n<p><b>Step 1:<\/b><span style=\"font-weight: 400;\"> Load credentials from AWS identity. See using<\/span><a href=\"https:\/\/docs.aws.amazon.com\/sdkref\/latest\/guide\/access-iam-roles-for-ec2.html\" target=\"_blank\" rel=\"nofollow noopener\"> <span style=\"font-weight: 400;\">IAM roles<\/span><\/a><span style=\"font-weight: 400;\">.<\/span><\/p>\n<p><b>Step2:<\/b><span style=\"font-weight: 400;\"> Load the shared credential file (~\/.aws\/credentials)<\/span><\/p>\n<p><b>[default]<\/b><\/p>\n<p><b>aws_access_key_id = &lt;YOUR_ACCESS_KEY_ID&gt;<\/b><\/p>\n<p><b>aws_secret_access_key = &lt;YOUR_SECRET_ACCESS_KEY&gt;<\/b><\/p>\n<p><b>Step 3:<\/b><span style=\"font-weight: 400;\"> Load from<\/span><a href=\"https:\/\/docs.aws.amazon.com\/sdkref\/latest\/guide\/environment-variables.html\" target=\"_blank\" rel=\"nofollow noopener\"> <span style=\"font-weight: 400;\">environmental variables<\/span><\/a><span style=\"font-weight: 400;\">: The SDK always detects any AWS credential set as a variable in your environment. This is used for requests and the variables include:<\/span><\/p>\n<p><b>AWS_ACCESS_KEY_ID<\/b><\/p>\n<p><b>AWS_SECRET_ACCESS_KEY<\/b><\/p>\n<p><b>\u00a0AWS_SESSION_TOKEN<\/b><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0<strong>Step 4<\/strong><\/span><b>:<\/b><span style=\"font-weight: 400;\"> Load from a JSON file on disk: This is achieved through using <\/span><b>AWS.config.loadFromPath<\/b><span style=\"font-weight: 400;\">. The specified path is relative to the working directory of your process. For example, loading credentials from \u2018config.json\u2019 file will require you to run this command:<\/span><\/p>\n<p><b>{ &#8220;accessKeyId&#8221;: &lt;YOUR_ACCESS_KEY_ID&gt;, &#8220;secretAccessKey&#8221;: &lt;YOUR_SECRET_ACCESS_KEY&gt;,<\/b><\/p>\n<p><b>&#8220;region&#8221;: &#8220;us-east-1&#8221; }<\/b><\/p>\n<p><span style=\"font-weight: 400;\">Followed by the code:<\/span><\/p>\n<p><b>var AWS = require(&#8220;aws-sdk&#8221;);<\/b><\/p>\n<p><b>AWS.config.loadFromPath(&#8216;.\/config.json&#8217;);<\/b><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0<strong>Step 5<\/strong><\/span><b>:<\/b><span style=\"font-weight: 400;\"> Other credentials provided by the SDK. You can also get credentials from specifying the credential process in the AWS config file. The set <\/span><b>AWS_SDK_LOAD_CONFIG <\/b><span style=\"font-weight: 400;\">environment variable will be prioritized to the specified credentials file if there is any. See<\/span><a href=\"https:\/\/docs.aws.amazon.com\/cli\/latest\/topic\/config-vars.html#sourcing-credentials-from-external-processes\" target=\"_blank\" rel=\"nofollow noopener\"> <span style=\"font-weight: 400;\">External Processes in sourcing credentials<\/span><\/a><span style=\"font-weight: 400;\"> to learn more.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0<\/span><span style=\"font-weight: 400;\">In the event of an SDK with more than one credential source, then the default selection will be loaded as follows:<\/span><\/p>\n<ol>\n<li><span style=\"font-weight: 400;\"> \u00a0 \u00a0 Credentials set through service-client constructor<\/span><\/li>\n<li><span style=\"font-weight: 400;\"> \u00a0 \u00a0 Environment variables<\/span><\/li>\n<li><span style=\"font-weight: 400;\"> \u00a0 \u00a0 Shared credentials<\/span><\/li>\n<li><span style=\"font-weight: 400;\"> \u00a0 \u00a0 Credentials from ECS<\/span><\/li>\n<li><span style=\"font-weight: 400;\"> \u00a0 \u00a0 Credentials specified in the shared AWS configuration file<\/span><\/li>\n<li><span style=\"font-weight: 400;\"> \u00a0 \u00a0 Credentials loaded from AWS of Amazon EC2.<\/span><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\">Note that it is not recommended to hand code your AWS credentials in the application because it possesses the risk of exposing your secret access key and ID.<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Writing_the_Nodejs_Code\"><\/span><span style=\"font-weight: 400;\">Writing the Node.js Code<\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Proceed to create a new file <\/span><b>titled sample.js<\/b><span style=\"font-weight: 400;\"> for the example code. Add the <\/span><b>required<\/b><span style=\"font-weight: 400;\"> function calls for the SDK and <\/span><b>uuid<\/b><span style=\"font-weight: 400;\"> models to be made available for use. Add your unique ID value to a recognizable prefix to come up with a bucket name for creating an Amazon S3 bucket. In our example we have used \u2018node-sdk-sample-\u2019. Call the <\/span><b>uuid<\/b><span style=\"font-weight: 400;\"> module to generate your unique ID and a name for the key parameter used to upload an object to the bucket.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Now create a <\/span><b>promise<\/b><span style=\"font-weight: 400;\"> object for you to be able to call the <\/span><b>createBucket<\/b><span style=\"font-weight: 400;\"> method of <\/span><b>AWS.S3<\/b><span style=\"font-weight: 400;\"> service object. Now create another promise so that you can call the <\/span><b>putObject<\/b><span style=\"font-weight: 400;\"> method for you to upload text to the bucket. Here is a sample of the same that can also be found in<\/span><a href=\"https:\/\/github.com\/awsdocs\/aws-doc-sdk-examples\/blob\/main\/javascript\/example_code\/nodegetstarted\/sample.js\" target=\"_blank\" rel=\"nofollow noopener\"> <span style=\"font-weight: 400;\">GitHub<\/span><\/a><span style=\"font-weight: 400;\">.<\/span><\/p>\n<p><b>\/\/ Load the SDK and UUID<\/b><\/p>\n<p><b>var AWS = require(&#8220;aws-sdk&#8221;);<\/b><\/p>\n<p><b>var uuid = require(&#8220;uuid&#8221;);<\/b><\/p>\n<p><b>\/\/ Create unique bucket name<\/b><\/p>\n<p><b>var bucketName = &#8220;node-sdk-sample-&#8221; + uuid.v4();<\/b><\/p>\n<p><b>\/\/ Create name for uploaded object key<\/b><\/p>\n<p><b>var keyName = &#8220;hello_world.txt&#8221;;<\/b><\/p>\n<p><b>\/\/ Create a promise on S3 service object<\/b><\/p>\n<p><b>var bucketPromise = new AWS.S3({ apiVersion: &#8220;2006-03-01&#8221; })<\/b><\/p>\n<p><b>\u00a0\u00a0.createBucket({ Bucket: bucketName })<\/b><\/p>\n<p><b>\u00a0\u00a0.promise();<\/b><\/p>\n<p><b>\/\/ Handle promise fulfilled\/rejected states<\/b><\/p>\n<p><b>bucketPromise<\/b><\/p>\n<p><b>\u00a0\u00a0.then(function (data) {<\/b><\/p>\n<p><b>\/\/ Create params for putObject call<\/b><\/p>\n<p><b>var objectParams = {<\/b><\/p>\n<p><b>\u00a0\u00a0<\/b> <b>Bucket: bucketName,<\/b><\/p>\n<p><b>\u00a0\u00a0<\/b> <b>Key: keyName,<\/b><\/p>\n<p><b>\u00a0\u00a0<\/b> <b>Body: &#8220;Hello World!&#8221;,<\/b><\/p>\n<p><b>};<\/b><\/p>\n<p><b>\/\/ Create object upload promise<\/b><\/p>\n<p><b>var uploadPromise = new AWS.S3({ apiVersion: &#8220;2006-03-01&#8221; })<\/b><\/p>\n<p><b>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.putObject(objectParams)<\/b><\/p>\n<p><b>\u00a0\u00a0<\/b> <b>.promise();<\/b><\/p>\n<p><b>\u00a0\u00a0\u00a0\u00a0uploadPromise.then(function (data) {<\/b><\/p>\n<p><b>\u00a0\u00a0<\/b> <b>console.log(<\/b><\/p>\n<p><b>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#8220;Successfully uploaded data to &#8221; + bucketName + &#8220;\/&#8221; + keyName<\/b><\/p>\n<p><b>\u00a0\u00a0<\/b> <b>);<\/b><\/p>\n<p><b>});<\/b><\/p>\n<p><b>\u00a0\u00a0})<\/b><\/p>\n<p><b>\u00a0\u00a0.catch(function (err) {<\/b><\/p>\n<p><b>\u00a0\u00a0\u00a0\u00a0console.error(err, err.stack);<\/b><\/p>\n<p><b>\u00a0\u00a0});<\/b><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0<\/span><b>Running the Sample<\/b><\/p>\n<p><span style=\"font-weight: 400;\">Finally, type this command to run the sample:<\/span><\/p>\n<p><b>node sample.js<\/b><\/p>\n<p><span style=\"font-weight: 400;\">Successful uploads prompt confirmation messages at the command line. You can also access the bucket and text object in the<\/span><a href=\"https:\/\/console.aws.amazon.com\/s3\/\" target=\"_blank\" rel=\"nofollow noopener\"> <span style=\"font-weight: 400;\">Amazon S3 console<\/span><\/a><span style=\"font-weight: 400;\">.<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"_Verifying_Versions_of_TLS\"><\/span><span style=\"font-weight: 400;\">\u00a0<\/span><span style=\"font-weight: 400;\">Verifying Versions of TLS<\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">To verify the version of OpenSSL and TLS used by Node.js on your device:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Run this command for OpenSSL:<\/span><\/p>\n<p><b>node -p process.versions<\/b><\/p>\n<p><span style=\"font-weight: 400;\">You will expect to get the following results:<\/span><\/p>\n<p><b>openssl: &#8216;1.1.1b&#8217;<\/b><\/p>\n<p><span style=\"font-weight: 400;\">Run this command for TSL:<\/span><\/p>\n<p><b>&gt; var tls = require(&#8220;tls&#8221;);<\/b><\/p>\n<p><b>&gt; var tlsSocket = new tls.TLSSocket();<\/b><\/p>\n<p><b>&gt; tlsSocket.getProtocol();<\/b><\/p>\n<p><span style=\"font-weight: 400;\">The last output should read:<\/span><\/p>\n<p><b>&#8216;TLSv1.3&#8217;<\/b><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span><span style=\"font-weight: 400;\">Conclusion<\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">In this blog, we&#8217;ve explored how integrating AWS SDKs into your Node.js applications can significantly enhance your development capabilities and leverage AWS&#8217;s robust cloud infrastructure. By following the detailed steps provided, you can efficiently set up your environment, manage dependencies, and securely configure your application to interact seamlessly with AWS services. Whether you&#8217;re deploying simple serverless functions or building complex, scalable applications, mastering these integration techniques will greatly improve your productivity and efficiency.<\/span><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Integrating AWS SDKs into your Node.js application opens up a world of possibilities, allowing you to leverage the power and scalability of AWS services directly from your code. Whether you are creating serverless functions, deploying applications on EC2, or managing resources with Elastic Beanstalk, understanding how to set up and use AWS SDKs is crucial. \u00a0For those aiming to become an AWS Certified Developer Associate, mastering these skills is essential. In this guide, we will walk you through the process of setting up an AWS Node.js environment, installing necessary SDKs and dependencies, configuring credentials securely, and writing and running your [&hellip;]<\/p>\n","protected":false},"author":408,"featured_media":97053,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"default","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[10],"tags":[5208,5209],"class_list":["post-97046","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cloud-computing-certifications","tag-aws-sdk-node-js-integration","tag-aws-sdk-setup-node-js"],"uagb_featured_image_src":{"full":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2024\/08\/AWS-Node-JS-1-scaled.webp",2560,1280,false],"thumbnail":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2024\/08\/AWS-Node-JS-1-150x150.webp",150,150,true],"medium":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2024\/08\/AWS-Node-JS-1-300x150.webp",300,150,true],"medium_large":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2024\/08\/AWS-Node-JS-1-768x384.webp",768,384,true],"large":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2024\/08\/AWS-Node-JS-1-1024x512.webp",1024,512,true],"1536x1536":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2024\/08\/AWS-Node-JS-1-1536x768.webp",1536,768,true],"2048x2048":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2024\/08\/AWS-Node-JS-1-2048x1024.webp",2048,1024,true],"profile_24":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2024\/08\/AWS-Node-JS-1-scaled.webp",24,12,false],"profile_48":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2024\/08\/AWS-Node-JS-1-scaled.webp",48,24,false],"profile_96":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2024\/08\/AWS-Node-JS-1-scaled.webp",96,48,false],"profile_150":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2024\/08\/AWS-Node-JS-1-scaled.webp",150,75,false],"profile_300":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2024\/08\/AWS-Node-JS-1-scaled.webp",300,150,false],"tptn_thumbnail":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2024\/08\/AWS-Node-JS-1-250x250.webp",250,250,true],"web-stories-poster-portrait":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2024\/08\/AWS-Node-JS-1-640x853.webp",640,853,true],"web-stories-publisher-logo":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2024\/08\/AWS-Node-JS-1-96x96.webp",96,96,true],"web-stories-thumbnail":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2024\/08\/AWS-Node-JS-1-150x75.webp",150,75,true]},"uagb_author_info":{"display_name":"Anitha Dorairaj","author_link":"https:\/\/www.whizlabs.com\/blog\/author\/anitha-dorairaj\/"},"uagb_comment_info":4,"uagb_excerpt":"Integrating AWS SDKs into your Node.js application opens up a world of possibilities, allowing you to leverage the power and scalability of AWS services directly from your code. Whether you are creating serverless functions, deploying applications on EC2, or managing resources with Elastic Beanstalk, understanding how to set up and use AWS SDKs is crucial.&hellip;","_links":{"self":[{"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/posts\/97046","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/users\/408"}],"replies":[{"embeddable":true,"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/comments?post=97046"}],"version-history":[{"count":7,"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/posts\/97046\/revisions"}],"predecessor-version":[{"id":97057,"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/posts\/97046\/revisions\/97057"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/media\/97053"}],"wp:attachment":[{"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/media?parent=97046"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/categories?post=97046"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/tags?post=97046"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}