id
stringlengths
14
16
text
stringlengths
1
2.43k
source
stringlengths
99
229
90c95d30fb21-0
After you install Node\.js on an Amazon EC2 instance, you can create an Amazon Machine Image \(AMI\) from that instance\. Creating an AMI makes it easy to provision multiple Amazon EC2 instances with the same Node\.js installation\. For more information about creating an AMI from an existing instance, see [Creating an Amazon EBS\-Backed Linux AMI](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/creating-an-ami-ebs.html) in the *Amazon EC2 User Guide for Linux Instances*\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/setting-up-node-on-ec2-instance.md
6828944d38ee-0
For more information about the commands and software used in this topic, see the following webpages: + Node Version Manager \(`nvm`\): see [nvm repo on GitHub](https://github.com/creationix/nvm)\. + Node Package Manager \(`npm`\): see [npm website](https://www.npmjs.com)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/setting-up-node-on-ec2-instance.md
92fadea2a7ef-0
In this task, you run the application you created starting with [Tutorial: Creating and Using Lambda Functions](using-lambda-functions.md)\. **To run the browser application** 1. Open a web browser\. 1. Point the browser at the URL for the Amazon S3 bucket that hosts the application\. ![\[Slot machine web application running in a browser that invokes a Lambda function\]](http://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/images/app_02.png)![\[Slot machine web application running in a browser that invokes a Lambda function\]](http://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/)![\[Slot machine web application running in a browser that invokes a Lambda function\]](http://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/) 1. Select the handle on the right side of the slot machine\. The wheels begin to spin as the browser script invokes the Lambda function to generate results for this turn\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/running-lambda-function.md
92fadea2a7ef-1
1. Select the handle on the right side of the slot machine\. The wheels begin to spin as the browser script invokes the Lambda function to generate results for this turn\. ![\[Web application running in a browser that invokes a Lambda function.\]](http://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/images/app_01.png)![\[Web application running in a browser that invokes a Lambda function.\]](http://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/)![\[Web application running in a browser that invokes a Lambda function.\]](http://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/) 1. Once the Lambda function returns the spin results to the browser script, the browser script sets the game display to show the images that the Lambda function selected\. 1. Select the handle again to start another spin\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/running-lambda-function.md
03bbd008e33d-0
To avoid ongoing charges for the resources and services used in this tutorial, delete the following resources in their respective service consoles: + The Lambda function in the AWS Lambda console at [https://console\.aws\.amazon\.com/lambda/](https://console.aws.amazon.com/lambda/)\. + The DynamoDB table in the Amazon DynamoDB console at [https://console\.aws\.amazon\.com/dynamodb/](https://console.aws.amazon.com/dynamodb/)\. + The objects in the Amazon S3 bucket and the bucket itself in the Amazon S3 console at [https://console\.aws\.amazon\.com/s3/](https://console.aws.amazon.com/s3/)\. + The Amazon Cognito identity pool in the Amazon Cognito console at [https://console\.aws\.amazon\.com/cognito/](https://console.aws.amazon.com/cognito/)\. + The Lambda execution role in the IAM console at [https://console\.aws\.amazon\.com/iam/](https://console.aws.amazon.com/iam/)\. Congratulations\! You have now finished the tutorial\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/running-lambda-function.md
dcf8041e252f-0
The topics in this section contain examples of how to use the AWS SDK for JavaScript with the APIs of various services to carry out common tasks\. Find the source code for these examples and others in the AWS documentation [code examples repository on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples)\. To propose a new code example for the AWS documentation team to consider producing, create a request\. The team is looking to produce code examples that cover broader scenarios and use cases, versus simple code snippets that cover only individual API calls\. For instructions, see the *Proposing new code examples* section in the [Readme on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/README.rst)\. **Topics** + [Amazon CloudWatch Examples](cloudwatch-examples.md) + [Amazon DynamoDB Examples](dynamodb-examples.md) + [Amazon EC2 Examples](ec2-examples.md) + [AWS Elemental MediaConvert Examples](emc-examples.md) + [Amazon S3 Glacier Examples](glacier-examples.md) + [AWS Identity and Access Management Examples](iam-examples.md) + [Amazon Kinesis Example](kinesis-examples.md) + [AWS Lambda Examples](lambda-examples.md) + [Amazon S3 Examples](s3-examples.md)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/sdk-code-samples.md
dcf8041e252f-1
+ [AWS Lambda Examples](lambda-examples.md) + [Amazon S3 Examples](s3-examples.md) + [Amazon Simple Email Service Examples](ses-examples.md) + [Amazon Simple Notification Service Examples](sns-examples.md) + [Amazon SQS Examples](sqs-examples.md)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/sdk-code-samples.md
1818c5acf128-0
Install Node\.js on your servers if it is not already installed\. **Topics** + [Setting Up an AWS Node\.js Environment](setting-up-node.md) + [Supported Web Browsers](browsers-supported.md)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/jssdk-prerequisites.md
25fc3a693a4d-0
To set up an AWS Node\.js environment in which you can run your application, use any of the following methods: + Choose an Amazon Machine Image \(AMI\) with Node\.js pre\-installed and create an Amazon EC2 instance using that AMI\. When creating your Amazon EC2 instance, choose your AMI from the AWS Marketplace\. Search the AWS Marketplace for Node\.js and choose an AMI option that includes a version of Node\.js \(32\-bit or 64\-bit\) preinstalled\. + Create an Amazon EC2 instance and install Node\.js on it\. For more information about how to install Node\.js on an Amazon Linux instance, see [Tutorial: Setting Up Node\.js on an Amazon EC2 Instance](setting-up-node-on-ec2-instance.md)\. + Create a serverless environment using AWS Lambda to run Node\.js as a Lambda function\. For more information about using Node\.js within a Lambda function, see [Programming Model \(Node\.js\)](https://docs.aws.amazon.com/lambda/latest/dg/programming-model.html) in the *AWS Lambda Developer Guide*\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/setting-up-node.md
25fc3a693a4d-1
+ Deploy your Node\.js application to AWS Elastic Beanstalk\. For more information about using Node\.js with Elastic Beanstalk, see [Deploying Node\.js Applications to AWS Elastic Beanstalk](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_nodejs.html) in the *AWS Elastic Beanstalk Developer Guide*\. + Create a Node\.js application server using AWS OpsWorks\. For more information about using Node\.js with AWS OpsWorks, see [Creating Your First Node\.js Stack](https://docs.aws.amazon.com/opsworks/latest/userguide/gettingstarted-node.html) in the *AWS OpsWorks User Guide*\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/setting-up-node.md
39c62d112752-0
JSON is a format for data exchange that is both human\-readable and machine\-readable\. Although the name JSON is an acronym for *JavaScript Object Notation*, the format of JSON is independent of any programming language\. The AWS SDK for JavaScript uses JSON to send data to service objects when making requests and receives data from service objects as JSON\. For more information about JSON, see [json\.org](https://json.org)\. ![\[Showing the general format and parts of JSON.\]](http://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/images/json-format.png) JSON represents data in two ways: + As an *object*, which is an unordered collection of name\-value pairs\. An object is defined within left \(`{`\) and right \(`}`\) braces\. Each name\-value pair begins with the name, followed by a colon, followed by the value\. Name\-value pairs are comma separated\. + As an *array*, which is an ordered collection of values\. An array is defined within left \(`[`\) and right \(`]`\) brackets\. Items in the array are comma separated\. Here is an example of a JSON object that contains an array of objects in which the objects represent cards in a card game\. Each card is defined by two name\-value pairs, one that specifies a unique value to identify that card and another that specifies a URL that points to the corresponding card image\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/working-with-json.md
39c62d112752-1
``` var cards = [{"CardID":"defaultname", "Image":"defaulturl"}, {"CardID":"defaultname", "Image":"defaulturl"}, {"CardID":"defaultname", "Image":"defaulturl"}, {"CardID":"defaultname", "Image":"defaulturl"}, {"CardID":"defaultname", "Image":"defaulturl"}]; ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/working-with-json.md
0699d98d1605-0
Here is an example of simple JSON used to define the parameters of a call to an AWS Lambda service object\. ``` const params = { FunctionName : 'slotPull', InvocationType : 'RequestResponse', LogType : 'None' }; ``` The `params` object is defined by three name\-value pairs, separated by commas within the left and right braces\. When providing parameters to a service object method call, the names are determined by the parameter names for the service object method you plan to call\. When invoking a Lambda function, `FunctionName`, `InvocationType`, and `LogType` are the parameters used to call the `invoke` method on a Lambda service object\. When passing parameters to a service object method call, provide the JSON object to the method call, as shown in the following example of invoking a Lambda function\. ``` (async function() { const { LambdaClient, InvokeCommand } = require('@aws-sdk/client-lambda') const lambdaClient = new LambdaClient({ region: 'us-west-2' }) // create JSON object for service call parameters var params = { FunctionName : 'slotPull', InvocationType : 'RequestResponse', LogType : 'None' } // create InvokeCommand command
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/working-with-json.md
0699d98d1605-1
LogType : 'None' } // create InvokeCommand command const command = new InvokeCommand(command) // invoke Lambda function try { const response = await lambdaClient.send(params) console.log(response) } catch (err) { console.err(err); } })() ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/working-with-json.md
76267e0b10a7-0
![\[JavaScript code example that applies to browser execution\]](http://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/images/browsericon.png) **This browser script code example shows:** + How to create a browser application that allows users to create photo albums in an Amazon S3 bucket and upload photos into the albums\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-photo-album.md
649b3959908f-0
In this example, a simple HTML page provides a browser\-based application for creating photo albums in an Amazon S3 bucket into which you can upload photos\. The application lets you delete photos and albums that you add\. ![\[JavaScript in a browser script using Amazon S3 buckets for photo albums.\]](http://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/images/s3-photo-album-example.png) The browser script uses the SDK for JavaScript to interact with an Amazon S3 bucket\. Use the following methods of the Amazon S3 client class to enable the photo album application: + [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#listObjects-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#listObjects-property) + [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#headObject-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#headObject-property)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-photo-album.md
649b3959908f-1
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#putObject-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#putObject-property) + [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#upload-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#upload-property) + [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#deleteObject-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#deleteObject-property) + [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#deleteObjects-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#deleteObjects-property)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-photo-album.md
4df84c54456b-0
To set up and run this example, you must first complete these tasks: + In the [Amazon S3 console](https://console.aws.amazon.com/s3/), create an Amazon S3 bucket that you will use to store the photos in the album\. For more information about creating a bucket in the console, see [Creating a Bucket](https://docs.aws.amazon.com/AmazonS3/latest/user-guide/create-bucket.html) in the *Amazon Simple Storage Service Console User Guide*\. Make sure you have both **Read** and **Write** permissions on **Objects**\. + In the [Amazon Cognito console](https://console.aws.amazon.com/cognito/), create an Amazon Cognito identity pool using Federated Identities with access enabled for unauthenticated users in the same Region as the Amazon S3 bucket\. You need to include the identity pool ID in the code to obtain credentials for the browser script\. For more information about Amazon Cognito Federated Identities, see [Amazon Cognito Identity Pools \(Federated Identites\)](https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-identity.html) in the *Amazon Cognito Developer Guide*\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-photo-album.md
4df84c54456b-1
+ In the [IAM console](https://console.aws.amazon.com/iam/), find the IAM role created by Amazon Cognito for unauthenticated users\. Add the following policy to grant read and write permissions to an Amazon S3 bucket\. For more information about creating an IAM role, see [Creating a Role to Delegate Permissions to an AWS Service](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_create_for-service.html) in the *IAM User Guide*\. Use this role policy for the IAM role created by Amazon Cognito for unauthenticated users\. **Warning** If you enable access for unauthenticated users, you will grant write access to the bucket, and all objects in the bucket, to anyone in the world\. This security posture is useful in this example to keep it focused on the primary goals of the example\. In many live situations, however, tighter security, such as using authenticated users and object ownership, is highly advisable\. ``` { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "s3:DeleteObject", "s3:GetObject", "s3:ListBucket", "s3:PutObject" ], "Resource": [
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-photo-album.md
4df84c54456b-2
"s3:ListBucket", "s3:PutObject" ], "Resource": [ "arn:aws:s3:::BUCKET_NAME/*" ] } ] } ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-photo-album.md
c8899f3b407f-0
Before the browser script can access the Amazon S3 bucket, you must first set up its [CORS configuration](browser-js-considerations.md#configuring-cors-s3-bucket) as follows\. ``` <?xml version="1.0" encoding="UTF-8"?> <CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <CORSRule> <AllowedOrigin>*</AllowedOrigin> <AllowedMethod>POST</AllowedMethod> <AllowedMethod>GET</AllowedMethod> <AllowedMethod>PUT</AllowedMethod> <AllowedMethod>DELETE</AllowedMethod> <AllowedMethod>HEAD</AllowedMethod> <AllowedHeader>*</AllowedHeader> </CORSRule> </CORSConfiguration> ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-photo-album.md
7c87da8845b8-0
The HTML for the photo upload application consists of a <div> element within which the browser script creates the upload user interface\. The first <script> element adds the SDK to the browser script\. The second <script> element adds the external JavaScript file that holds the browser script code\. ``` <!DOCTYPE html> <html> <head> <script src="https://sdk.amazonaws.com/js/aws-sdk-2.283.1.min.js"></script> <script src="./app.js"></script> <script> function getHtml(template) { return template.join('\n'); } listAlbums(); </script> </head> <body> <h1>My Photo Albums App</h1> <div id="app"></div> </body> </html> ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-photo-album.md
e9501f175008-0
Obtain the credentials needed to configure the SDK by calling the `CognitoIdentityCredentials` method, providing the Amazon Cognito identity pool ID\. Next, create an `AWS.S3` service object\. ``` var albumBucketName = "BUCKET_NAME"; var bucketRegion = "REGION"; var IdentityPoolId = "IDENTITY_POOL_ID"; AWS.config.update({ region: bucketRegion, credentials: new AWS.CognitoIdentityCredentials({ IdentityPoolId: IdentityPoolId }) }); var s3 = new AWS.S3({ apiVersion: "2006-03-01", params: { Bucket: albumBucketName } }); ``` Nearly all of the rest of the code in this example is organized into a series of functions that gather and present information about the albums in the bucket, upload and display photos uploaded into albums, and delete photos and albums\. Those functions are: + `listAlbums` + `createAlbum` + `viewAlbum` + `addPhoto` + `deleteAlbum` + `deletePhoto`
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-photo-album.md
0a8880975fcb-0
The application creates albums in the Amazon S3 bucket as objects whose keys begin with a forward slash character, indicating the object functions as a folder\. To list all the existing albums in the bucket, the application's `listAlbums` function calls the `listObjects` method of the `AWS.S3` service object while using `commonPrefix` so the call returns only objects used as albums\. The rest of the function takes the list of albums from the Amazon S3 bucket and generates the HTML needed to display the album list in the webpage\. It also enables deleting and opening individual albums\. ``` function listAlbums() { s3.listObjects({ Delimiter: "/" }, function(err, data) { if (err) { return alert("There was an error listing your albums: " + err.message); } else { var albums = data.CommonPrefixes.map(function(commonPrefix) { var prefix = commonPrefix.Prefix; var albumName = decodeURIComponent(prefix.replace("/", "")); return getHtml([ "<li>", "<span onclick=\"deleteAlbum('" + albumName + "')\">X</span>", "<span onclick=\"viewAlbum('" + albumName + "')\">", albumName,
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-photo-album.md
0a8880975fcb-1
"<span onclick=\"viewAlbum('" + albumName + "')\">", albumName, "</span>", "</li>" ]); }); var message = albums.length ? getHtml([ "<p>Click on an album name to view it.</p>", "<p>Click on the X to delete the album.</p>" ]) : "<p>You do not have any albums. Please Create album."; var htmlTemplate = [ "<h2>Albums</h2>", message, "<ul>", getHtml(albums), "</ul>", "<button onclick=\"createAlbum(prompt('Enter Album Name:'))\">", "Create New Album", "</button>" ]; document.getElementById("app").innerHTML = getHtml(htmlTemplate); } }); } ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-photo-album.md
b8a20f7fc129-0
To create an album in the Amazon S3 bucket, the application's `createAlbum` function first validates the name given for the new album to ensure it contains suitable characters\. The function then forms an Amazon S3 object key, passing it to the `headObject` method of the Amazon S3 service object\. This method returns the metadata for the specified key, so if it returns data, then an object with that key already exists\. If the album doesn't already exist, the function calls the `putObject` method of the `AWS.S3` service object to create the album\. It then calls the `viewAlbum` function to display the new empty album\. ``` function createAlbum(albumName) { albumName = albumName.trim(); if (!albumName) { return alert("Album names must contain at least one non-space character."); } if (albumName.indexOf("/") !== -1) { return alert("Album names cannot contain slashes."); } var albumKey = encodeURIComponent(albumName) + "/"; s3.headObject({ Key: albumKey }, function(err, data) { if (!err) { return alert("Album already exists."); } if (err.code !== "NotFound") {
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-photo-album.md
b8a20f7fc129-1
return alert("Album already exists."); } if (err.code !== "NotFound") { return alert("There was an error creating your album: " + err.message); } s3.putObject({ Key: albumKey }, function(err, data) { if (err) { return alert("There was an error creating your album: " + err.message); } alert("Successfully created album."); viewAlbum(albumName); }); }); } ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-photo-album.md
db91aaa53e70-0
To display the contents of an album in the Amazon S3 bucket, the application's `viewAlbum` function takes an album name and creates the Amazon S3 key for that album\. The function then calls the `listObjects` method of the `AWS.S3` service object to obtain a list of all the objects \(photos\) in the album\. The rest of the function takes the list of objects \(photos\) from the album and generates the HTML needed to display the photos in the webpage\. It also enables deleting individual photos and navigating back to the album list\. ``` function viewAlbum(albumName) { var albumPhotosKey = encodeURIComponent(albumName) + "//"; s3.listObjects({ Prefix: albumPhotosKey }, function(err, data) { if (err) { return alert("There was an error viewing your album: " + err.message); } // 'this' references the AWS.Response instance that represents the response var href = this.request.httpRequest.endpoint.href; var bucketUrl = href + albumBucketName + "/"; var photos = data.Contents.map(function(photo) { var photoKey = photo.Key; var photoUrl = bucketUrl + encodeURIComponent(photoKey); return getHtml([ "<span>",
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-photo-album.md
db91aaa53e70-1
return getHtml([ "<span>", "<div>", '<img style="width:128px;height:128px;" src="' + photoUrl + '"/>', "</div>", "<div>", "<span onclick=\"deletePhoto('" + albumName + "','" + photoKey + "')\">", "X", "</span>", "<span>", photoKey.replace(albumPhotosKey, ""), "</span>", "</div>", "</span>" ]); }); var message = photos.length ? "<p>Click on the X to delete the photo</p>" : "<p>You do not have any photos in this album. Please add photos.</p>"; var htmlTemplate = [ "<h2>", "Album: " + albumName, "</h2>", message, "<div>", getHtml(photos), "</div>",
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-photo-album.md
db91aaa53e70-2
message, "<div>", getHtml(photos), "</div>", '<input id="photoupload" type="file" accept="image/*">', '<button id="addphoto" onclick="addPhoto(\'' + albumName + "')\">", "Add Photo", "</button>", '<button onclick="listAlbums()">', "Back To Albums", "</button>" ]; document.getElementById("app").innerHTML = getHtml(htmlTemplate); }); } ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-photo-album.md
53529095c55a-0
To upload a photo to an album in the Amazon S3 bucket, the application's `addPhoto` function uses a file picker element in the webpage to identify a file to upload\. It then forms a key for the photo to upload from the current album name and the file name\. The function calls the `upload` method of the Amazon S3 service object to upload the photo\. The `ACL` parameter is set to `public-read` so the application can fetch the photos in an album for display by their URL in the bucket\. After uploading the photo, the function redisplays the album so the uploaded photo appears\. ``` function addPhoto(albumName) { var files = document.getElementById("photoupload").files; if (!files.length) { return alert("Please choose a file to upload first."); } var file = files[0]; var fileName = file.name; var albumPhotosKey = encodeURIComponent(albumName) + "//"; var photoKey = albumPhotosKey + fileName; // Use S3 ManagedUpload class as it supports multipart uploads var upload = new AWS.S3.ManagedUpload({ params: { Bucket: albumBucketName, Key: photoKey, Body: file, ACL: "public-read" }
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-photo-album.md
53529095c55a-1
Key: photoKey, Body: file, ACL: "public-read" } }); var promise = upload.promise(); promise.then( function(data) { alert("Successfully uploaded photo."); viewAlbum(albumName); }, function(err) { return alert("There was an error uploading your photo: ", err.message); } ); } ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-photo-album.md
c3c82a52da61-0
To delete a photo from an album in the Amazon S3 bucket, the application's `deletePhoto` function calls the `deleteObject` method of the Amazon S3 service object\. This deletes the photo specified by the `photoKey` value passed to the function\. ``` function deletePhoto(albumName, photoKey) { s3.deleteObject({ Key: photoKey }, function(err, data) { if (err) { return alert("There was an error deleting your photo: ", err.message); } alert("Successfully deleted photo."); viewAlbum(albumName); }); } ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-photo-album.md
6d4d14ffdd4f-0
To delete an album in the Amazon S3 bucket, the application's `deleteAlbum` function calls the `deleteObjects` method of the Amazon S3 service object\. ``` function deleteAlbum(albumName) { var albumKey = encodeURIComponent(albumName) + "/"; s3.listObjects({ Prefix: albumKey }, function(err, data) { if (err) { return alert("There was an error deleting your album: ", err.message); } var objects = data.Contents.map(function(object) { return { Key: object.Key }; }); s3.deleteObjects( { Delete: { Objects: objects, Quiet: true } }, function(err, data) { if (err) { return alert("There was an error deleting your album: ", err.message); } alert("Successfully deleted album."); listAlbums(); } ); }); } ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-photo-album.md
f10fcf2fe1d5-0
The AWS SDK for JavaScript provides access to web services in either browser scripts or Node\.js\. This section has two getting started exercises that show you how to work with the SDK for JavaScript in each of these JavaScript environments\. You can also develop Node\.js applications using the SDK for JavaScript in the AWS Cloud9 IDE\. For an example of how to use AWS Cloud9 for Node\.js development, see [Node\.js Sample for AWS Cloud9](https://docs.aws.amazon.com/cloud9/latest/user-guide/sample-nodejs.html) in the *AWS Cloud9 User Guide*\. **Topics** + [Getting Started in a Browser Script](getting-started-browser.md) + [Getting Started in Node\.js](getting-started-nodejs.md)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/getting-started.md
42f6fb04fb47-0
Although Node\.js code is JavaScript, using the AWS SDK for JavaScript in Node\.js can differ from using the SDK in browser scripts\. Some API methods work in Node\.js but not in browser scripts, as well as the other way around\. And successfully using some APIs depends on your familiarity with common Node\.js coding patterns, such as importing and using other Node\.js modules like the `File System (fs)` module\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/node-js-considerations.md
5a1530471dea-0
Node\.js provides a collection of built\-in modules you can use without installing them\. To use these modules, create an object with the `require` method to specify the module name\. For example, to include the built\-in HTTP module, use the following\. ``` var http = require('http'); ``` Invoke methods of the module as if they are methods of that object\. For example, here is code that reads an HTML file\. ``` // include File System module var fs = require('fs'); // Invoke readFile method fs.readFile('index.html', function(err, data) { if (err) { throw err; } else { // Successful file read } }); ``` For a complete list of all built\-in modules that Node\.js provides, see [Node\.js v6\.11\.1 Documentation](https://nodejs.org/api/modules.html) on the Node\.js website\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/node-js-considerations.md
8ae2e22ae934-0
In addition to the built\-in modules, you can also include and incorporate third\-party code from `npm`, the Node\.js package manager\. This is a repository of open source Node\.js packages and a command\-line interface for installing those packages\. For more information about `npm` and a list of currently available packages, see [https://www\.npmjs\.com](https://www.npmjs.com)\. You can also learn about additional Node\.js packages you can use [here on GitHub](https://github.com/sindresorhus/awesome-nodejs)\. **Topics** + [Using Built\-In Node\.js Modules](#node-common-modules) + [Using npm Packages](#node-npm-packages) + [Configuring maxSockets in Node\.js](node-configuring-maxsockets.md) + [Reusing Connections with Keep\-Alive in Node\.js](node-reusing-connections.md) + [Configuring Proxies for Node\.js](node-configuring-proxies.md) + [Registering Certificate Bundles in Node\.js](node-registering-certs.md)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/node-js-considerations.md
18013b8268cf-0
Each service object method can accept an anonymous callback function as the last parameter\. The signature of this callback function is as follows\. ``` function(error, data) { // callback handling code } ``` This callback function executes when either a successful response or error data returns\. If the method call succeeds, the contents of the response are available to the callback function in the `data` parameter\. If the call doesn't succeed, the details about the failure are provided in the `error` parameter\. Typically the code inside the callback function tests for an error, which it processes if one is returned\. If an error is not returned, the code then retrieves the data in the response from the `data` parameter\. The basic form of the callback function looks like this example\. ``` function(error, data) { if (error) { // error handling code console.log(error); } else { // data handling code console.log(data); } } ``` In the previous example, the details of either the error or the returned data are logged to the console\. Here is an example that shows a callback function passed as part of calling a method on a service object\. ``` ec2.describeInstances(function(error, data) { if (error) { console.log(error); // an error occurred
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/using-a-callback-function.md
18013b8268cf-1
if (error) { console.log(error); // an error occurred } else { console.log(data); // request succeeded } }); ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/using-a-callback-function.md
1c65e13d2c31-0
There are a number of paths you can take to migrate to the SDK for JavaScript version 3\. For new code we recommend level 2\. ------
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/migrating-to-v2.md
4de2dd8d2c35-0
Do nothing\. The SDK supports almost all of the existing code paths\. ------
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/migrating-to-v2.md
e040402a5401-0
Perform minimal changes: + Install only the service\-specific packages you need\. + Create and use V3 service clients, replacing the use of any global configuration values, such as Region, with configuration values passed in as arguments to the client\. ------
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/migrating-to-v2.md
b77d1b7b199a-0
Level 1 plus use the asynch/await programming model\. ------ The details of these changes are described in the following sections\. **Note** Many of the code examples in the guide have not been migrated to version 3\. To take full advantage of V3 features, make the Level 2 changes to the V2 code examples before using them\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/migrating-to-v2.md
6aa8138cc2a7-0
The following example installs the package for Amazon S3\. ``` npm install @aws-sdk/client-s3 ``` The following example loads the Amazon S3 service\. ``` const S3 = require('@aws-sdk/client-s3') ``` The following example creates an Amazon S3 client\. ``` const s3Client = new S3.S3Client() ``` The following example creates an Amazon S3 client in the `us-west-2` Region\. ``` const s3Client = new S3.S3Client({region: 'us-west-2'}) ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/migrating-to-v2.md
b7d26b9e8131-0
For details about specifying a credential process in the shared AWS config file or the shared credentials file, see [Sourcing Credentials From External Processes](https://docs.aws.amazon.com/cli/latest/topic/config-vars.html#sourcing-credentials-from-external-processes)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/loading-node-credentials-configured-credential-process.md
f9e69a844578-0
The [AWS SDK for JavaScript API Reference](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/) provides a JavaScript API for AWS services\. You can use the JavaScript API to build libraries or applications for [Node\.js](https://nodejs.org/en/) or the browser\. ![\[Relationship between JavaScript environments, the SDK, and Amazon Web Services\]](http://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/images/sdk-overview-v3.png)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/welcome.md
9d8f1c6a4512-0
Version 3 of the SDK for JavaScript \(V3\) contains the following new features: Modularized Packages Users can now use a separate package for each service\. New Middleware Stack Users can now use a middleware stack to control the lifecycle of an operation call\. In addition, the SDK is written in TypeScript, which has many advantages, such as static typing\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/welcome.md
06216bfaa603-0
Version 2 of the SDK for JavaScript \(V2\) required you to use the entire AWS SDK, as follows\. ``` var AWS = require("aws-sdk"); ``` Loading the entire SDK isn’t an issue if your application is using many AWS services\. However, if you need to use only a few services, it means increasing the size of your application with code you don't need or use\. In V3, you can load and use only the individual services you need\. This is shown in the following example, which only gives you access to Amazon Simple Storage Service \(Amazon S3\)\. ``` const s3 = require("@aws-sdk/client-s3"); ``` Not only can you load and use individual services, but you can also load and use only the service commands you need\. This is shown in the following example, which only gives you access to the Amazon S3 client and `ListBucketsCommand` command\. ``` const { S3Client, ListBucketsCommand } = require('@aws-sdk/client-s3') ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/welcome.md
b755d661664c-0
In V2, a simple code example that lists all of your Amazon S3 buckets in the `us-west-2` Region might look like the following\. ``` var AWS = require("aws-sdk"); // Set the Region AWS.config.update({region: "us-west-2"}) // Create S3 service object s3Client = new AWS.S3({apiVersion: "2006-03-01"}) // List your buckets s3Client.listBuckets(function(err, data) { if (err) { console.log("Error", err); } else { console.log("Success", data.Buckets); } }) ``` V3 looks like the following\. ``` (async function () { const S3 = require('@aws-sdk/client-s3') const s3Client = new S3.S3Client({ region: 'us-west-2' }) const command = new S3.ListBucketsCommand({}) try { const results = await s3Client.send(command) results.Buckets.forEach(function (item, index) {
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/welcome.md
b755d661664c-1
const results = await s3Client.send(command) results.Buckets.forEach(function (item, index) { console.log(item.Name) }) } catch (err) { console.error(err) } })() ``` The `aws-sdk` package adds about 40 MB to your application\. Replacing `var AWS = require("aws-sdk")` with `const s3 = require("@aws-sdk/client-s3")` reduces that overhead to about 3MB\. Restricting the import to just the Amazon S3 client and `ListBucketsCommand` command reduces the overhead to less that 100KB: ``` // Load the S3 client and ListBucketsCommand command for Node.js const { S3Client, ListBucketsCommand } = require('@aws-sdk/client-s3') const s3Client = new S3Client({}) const listBucketsCommand = new ListBucketsCommand({}) ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/welcome.md
5f23576045e8-0
V2 of the SDK enabled modifying a request throughout the multiple stages of its lifecycle by attaching event listeners to the request\. This approach can make it difficult to debug what went wrong during a request’s lifecycle\. In V3, you can use a new middleware stack to control the lifecycle of an operation call\. This approach provides a couple of benefits\. Each middleware stage in the stack calls the next middleware stage after making any changes to the request object\. This also makes debugging issues in the stack much easier, because you can see exactly which middleware stages were called leading up to the error\. The following example adds a custom header to an AWS Lambda client using middleware\. The first argument is a function that accepts `next`, which is the next middleware stage in the stack to call, and `context`, which is an object that contains some information about the operation being called\. The function returns a function that accepts `args`, which is an object that contains the parameters passed to the operation and the request, and returns the result from calling the next middleware with `args`\. ``` lambda.middlewareStack.add( (next, context) => args => { args.request.headers["Custom-Header"] = "value"; return next(args); }, { step: "build" } ) lambda.send(new PutObjectCommand(params)) ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/welcome.md
13bc2ca81312-0
Node\.js is a cross\-platform runtime for running server\-side JavaScript applications\. You can set up Node\.js on an Amazon Elastic Compute Cloud \(Amazon EC2\) instance to run on a server\. You can also use Node\.js to write on\-demand AWS Lambda functions\. Using the SDK for Node\.js differs from the way in which you use it for JavaScript in a web browser\. The difference comes from the way in which you load the SDK and in how you obtain the credentials needed to access specific web services\. When use of particular APIs differs between Node\.js and the browser, those differences will be called out\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/welcome.md
7d10633c84a4-0
You can also develop Node\.js applications using the SDK for JavaScript in the AWS Cloud9 IDE\. For an example of how to use AWS Cloud9 for Node\.js development, see [Node\.js Sample for AWS Cloud9](https://docs.aws.amazon.com/cloud9/latest/user-guide//sample-nodejs.html) in the *AWS Cloud9 User Guide*\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/welcome.md
2bb42e95b9d1-0
For browser\-based web, mobile, and hybrid apps, you can also use the [AWS Amplify Library on GitHub](https://github.com/aws/aws-amplify)\. It extends the SDK for JavaScript, providing a declarative interface\. **Note** Frameworks such as Amplify might not offer the same browser support as the SDK for JavaScript\. See the framework's documentation for details\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/welcome.md
675586873914-0
All major web browsers support execution of JavaScript\. JavaScript code that is running in a web browser is often called *client\-side JavaScript*\. Using the SDK for JavaScript in a web browser differs from the way in which you use it for Node\.js\. The difference comes from the way in which you load the SDK and in how you obtain the credentials needed to access specific web services\. When use of particular APIs differs between Node\.js and the browser, those differences will be called out\. For a list of browsers that are supported by the AWS SDK for JavaScript, see [Supported Web Browsers](browsers-supported.md)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/welcome.md
bfcbd3f214ea-0
Using the SDK for JavaScript in browser scripts makes it possible to realize a number of compelling use cases\. Here are several ideas for things you can build in a browser application by using the SDK for JavaScript to access various web services\. + Build a custom console to AWS services in which you access and combine features across Regions and services to best meet your organizational or project needs\. + Use Amazon Cognito Identity to enable authenticated user access to your browser applications and websites, including use of third\-party authentication from Facebook and others\. + Use Amazon Kinesis to process click streams or other marketing data in real time\. + Use Amazon DynamoDB for serverless data persistence such as individual user preferences for website visitors or application users\. + Use AWS Lambda to encapsulate proprietary logic that you can invoke from browser scripts without downloading and revealing your intellectual property to users\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/welcome.md
9d3089a1a191-0
You can browse the SDK for JavaScript examples in the [AWS Code Sample Catalog](https://docs.aws.amazon.com/code-samples/latest/catalog/code-catalog-javascript.html)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/welcome.md
810f9b00057a-0
In addition to this guide, the following online resources are available for SDK for JavaScript developers\. + [AWS SDK for JavaScript API Reference](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/) + [JavaScript Developer Blog](https://aws.amazon.com/blogs/developer/category/programing-language/javascript/) + [AWS JavaScript Forum](https://forums.aws.amazon.com/forum.jspa?forumID=148) + [JavaScript examples in the AWS Code Catalog](https://docs.aws.amazon.com/code-samples/latest/catalog/code-catalog-javascript.html) + [Gitter Channel](https://gitter.im/aws/aws-sdk-js) + [Stack Overflow](https://stackoverflow.com/search?tab=newest&q=aws-sdk-js) + [Stack Overflow questions tagged aws\-sdk\-js](https://stackoverflow.com/questions/tagged/aws-sdk-js?sort=newest) + GitHub + [SDK Source](https://github.com/aws/aws-sdk-js-v3/) + [Documentation Source](https://github.com/awsdocs/aws-sdk-for-javascript-v3)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/welcome.md
6e241105cb13-0
This AWS product or service conforms to the AWS [shared responsibility model](http://aws.amazon.com/compliance/shared-responsibility-model/), which includes regulations and guidelines for data protection\. AWS is responsible for protecting the global infrastructure that runs all the AWS services\. AWS maintains control over data hosted on this infrastructure, including the security configuration controls for handling customer content and personal data\. AWS customers and APN partners, acting either as data controllers or data processors, are responsible for any personal data that they put in the AWS Cloud\. For data protection purposes, we recommend that you protect AWS account credentials and set up individual user accounts with AWS Identity and Access Management \(IAM\), so that each user is given only the permissions necessary to fulfill their job duties\. We also recommend that you secure your data in the following ways: + Use multi\-factor authentication \(MFA\) with each account\. + Use SSL/TLS to communicate with AWS resources\. + Set up API and user activity logging with AWS CloudTrail\. + Use AWS encryption solutions, along with all default security controls within AWS services\. + Use advanced managed security services such as Amazon Macie, which assists in discovering and securing personal data that is stored in Amazon S3\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/data-protection.md
6e241105cb13-1
+ Use advanced managed security services such as Amazon Macie, which assists in discovering and securing personal data that is stored in Amazon S3\. We strongly recommend that you never put sensitive identifying information, such as your customers' account numbers, into free\-form fields such as a **Name** field\. This includes when you work with this AWS product or service or other AWS services using the console, API, AWS CLI, or AWS SDKs\. Any data that you enter into this AWS product or service or other services might get picked up for inclusion in diagnostic logs\. When you provide a URL to an external server, don't include credentials information in the URL to validate your request to that server\. For more information about data protection, see the [AWS Shared Responsibility Model and GDPR](http://aws.amazon.com/blogs/security/the-aws-shared-responsibility-model-and-gdpr/) blog post on the *AWS Security Blog*\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/data-protection.md
c647911e3f12-0
The topics in this section explain how to install and load the SDK for JavaScript so you can access the web services supported by the SDK\. **Note** React Native developers should use AWS Amplify to create new projects on AWS\. See the [aws\-sdk\-react\-native](https://github.com/amazon-archives/aws-sdk-react-native) archive for details\. **Topics** + [Prerequisites](jssdk-prerequisites.md) + [Installing the SDK for JavaScript](installing-jssdk.md) + [Loading the SDK for JavaScript](loading-the-jssdk.md) + [Migrating Your Code to SDK for JavaScript V3](migrating-to-v2.md)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/setting-up.md
f650e509baa7-0
See [Tutorial: Creating and Using Lambda Functions](using-lambda-functions.md) for step\-by\-step instructions on how to create and use an AWS Lambda function\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/lambda-examples.md
caf682a3b137-0
![\[JavaScript code example that applies to Node.js execution\]](http://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/images/nodeicon.png) **This Node\.js code example shows:** + How to get and set SMS messaging preferences for Amazon SNS\. + How to check a phone number to see if it has opted out of receiving SMS messages\. + How to get a list of phone numbers that have opted out of receiving SMS messages\. + How to send an SMS message\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/sns-examples-sending-sms.md
b9151e3cc0e8-0
You can use Amazon SNS to send text messages, or SMS messages, to SMS\-enabled devices\. You can send a message directly to a phone number, or you can send a message to multiple phone numbers at once by subscribing those phone numbers to a topic and sending your message to the topic\. In this example, you use a series of Node\.js modules to publish SMS text messages from Amazon SNS to SMS\-enabled devices\. The Node\.js modules use the SDK for JavaScript to publish SMS messages using these methods of the `AWS.SNS` client class: + [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SNS.html#getSMSAttributes-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SNS.html#getSMSAttributes-property) + [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SNS.html#setSMSAttributes-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SNS.html#setSMSAttributes-property)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/sns-examples-sending-sms.md
b9151e3cc0e8-1
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SNS.html#checkIfPhoneNumberIsOptedOut-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SNS.html#checkIfPhoneNumberIsOptedOut-property) + [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SNS.html#listPhoneNumbersOptedOut-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SNS.html#listPhoneNumbersOptedOut-property) + [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SNS.html#publish-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SNS.html#publish-property)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/sns-examples-sending-sms.md
90185029a97a-0
To set up and run this example, you must first complete these tasks: + Install Node\.js\. For more information about installing Node\.js, see the [Node\.js website](http://nodejs.org)\. + Create a shared configurations file with your user credentials\. For more information about providing a credentials JSON file, see [Loading Credentials in Node\.js from the Shared Credentials File](loading-node-credentials-shared.md)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/sns-examples-sending-sms.md
65f32548c787-0
Use Amazon SNS to specify preferences for SMS messaging, such as how your deliveries are optimized \(for cost or for reliable delivery\), your monthly spending limit, how message deliveries are logged, and whether to subscribe to daily SMS usage reports\. These preferences are retrieved and set as SMS attributes for Amazon SNS\. In this example, use a Node\.js module to get the current SMS attributes in Amazon SNS\. Create a Node\.js module with the file name `sns_getsmstype.js`\. Configure the SDK as previously shown\. Create an object containing the parameters for getting SMS attributes, including the names of the individual attributes to get\. For details on available SMS attributes, see [SetSMSAttributes](https://docs.aws.amazon.com/sns/latest/api/API_SetSMSAttributes.html) in the Amazon Simple Notification Service API Reference\. This example gets the `DefaultSMSType` attribute, which controls whether SMS messages are sent as `Promotional`, which optimizes message delivery to incur the lowest cost, or as `Transactional`, which optimizes message delivery to achieve the highest reliability\. Pass the parameters to the `setTopicAttributes` method of the `AWS.SNS` client class\. To call the `getSMSAttributes` method, create a promise for invoking an Amazon SNS service object, passing the parameters object\. Then handle the `response` in the promise callback\. ``` // Load the AWS SDK for Node.js var AWS = require('aws-sdk');
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/sns-examples-sending-sms.md
65f32548c787-1
// Load the AWS SDK for Node.js var AWS = require('aws-sdk'); // Set region AWS.config.update({region: 'REGION'}); // Create SMS Attribute parameter you want to get var params = { attributes: [ 'DefaultSMSType', 'ATTRIBUTE_NAME' /* more items */ ] }; // Create promise and SNS service object var getSMSTypePromise = new AWS.SNS({apiVersion: '2010-03-31'}).getSMSAttributes(params).promise(); // Handle promise's fulfilled/rejected states getSMSTypePromise.then( function(data) { console.log(data); }).catch( function(err) { console.error(err, err.stack); }); ``` To run the example, type the following at the command line\. ``` node sns_getsmstype.js ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/sns-examples-sending-sms.md
65f32548c787-2
``` node sns_getsmstype.js ``` This example code can be found [here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/sns/sns_getsmstype.js)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/sns-examples-sending-sms.md
6313057c596f-0
In this example, use a Node\.js module to get the current SMS attributes in Amazon SNS\. Create a Node\.js module with the file name `sns_setsmstype.js`\. Configure the SDK as previously shown\. Create an object containing the parameters for setting SMS attributes, including the names of the individual attributes to set and the values to set for each\. For details on available SMS attributes, see [ SetSMSAttributes](https://docs.aws.amazon.com/sns/latest/api/API_SetSMSAttributes.html) in the Amazon Simple Notification Service API Reference\. This example sets the `DefaultSMSType` attribute to `Transactional`, which optimizes message delivery to achieve the highest reliability\. Pass the parameters to the `setTopicAttributes` method of the `AWS.SNS` client class\. To call the `getSMSAttributes` method, create a promise for invoking an Amazon SNS service object, passing the parameters object\. Then handle the `response` in the promise callback\. ``` // Load the AWS SDK for Node.js var AWS = require('aws-sdk'); // Set region AWS.config.update({region: 'REGION'}); // Create SMS Attribute parameters var params = { attributes: { /* required */ 'DefaultSMSType': 'Transactional', /* highest reliability */
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/sns-examples-sending-sms.md
6313057c596f-1
var params = { attributes: { /* required */ 'DefaultSMSType': 'Transactional', /* highest reliability */ //'DefaultSMSType': 'Promotional' /* lowest cost */ } }; // Create promise and SNS service object var setSMSTypePromise = new AWS.SNS({apiVersion: '2010-03-31'}).setSMSAttributes(params).promise(); // Handle promise's fulfilled/rejected states setSMSTypePromise.then( function(data) { console.log(data); }).catch( function(err) { console.error(err, err.stack); }); ``` To run the example, type the following at the command line\. ``` node sns_setsmstype.js ``` This example code can be found [here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/sns/sns_setsmstype.js)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/sns-examples-sending-sms.md
3c56d32529e0-0
In this example, use a Node\.js module to check a phone number to see if it has opted out from receiving SMS messages\. Create a Node\.js module with the file name `sns_checkphoneoptout.js`\. Configure the SDK as previously shown\. Create an object containing the phone number to check as a parameter\. This example sets the `PhoneNumber` parameter to specify the phone number to check\. Pass the object to the `checkIfPhoneNumberIsOptedOut` method of the `AWS.SNS` client class\. To call the `checkIfPhoneNumberIsOptedOut` method, create a promise for invoking an Amazon SNS service object, passing the parameters object\. Then handle the `response` in the promise callback\. ``` // Load the AWS SDK for Node.js var AWS = require('aws-sdk'); // Set region AWS.config.update({region: 'REGION'}); // Create promise and SNS service object var phonenumPromise = new AWS.SNS({apiVersion: '2010-03-31'}).checkIfPhoneNumberIsOptedOut({phoneNumber: 'PHONE_NUMBER'}).promise(); // Handle promise's fulfilled/rejected states phonenumPromise.then( function(data) { console.log("Phone Opt Out is " + data.isOptedOut); }).catch(
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/sns-examples-sending-sms.md
3c56d32529e0-1
function(data) { console.log("Phone Opt Out is " + data.isOptedOut); }).catch( function(err) { console.error(err, err.stack); }); ``` To run the example, type the following at the command line\. ``` node sns_checkphoneoptout.js ``` This example code can be found [here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/sns/sns_checkphoneoptout.js)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/sns-examples-sending-sms.md
7f2f5c86d160-0
In this example, use a Node\.js module to get a list of phone numbers that have opted out from receiving SMS messages\. Create a Node\.js module with the file name `sns_listnumbersoptedout.js`\. Configure the SDK as previously shown\. Create an empty object as a parameter\. Pass the object to the `listPhoneNumbersOptedOut` method of the `AWS.SNS` client class\. To call the `listPhoneNumbersOptedOut` method, create a promise for invoking an Amazon SNS service object, passing the parameters object\. Then handle the `response` in the promise callback\. ``` // Load the AWS SDK for Node.js var AWS = require('aws-sdk'); // Set region AWS.config.update({region: 'REGION'}); // Create promise and SNS service object var phonelistPromise = new AWS.SNS({apiVersion: '2010-03-31'}).listPhoneNumbersOptedOut({}).promise(); // Handle promise's fulfilled/rejected states phonelistPromise.then( function(data) { console.log(data); }).catch( function(err) { console.error(err, err.stack); } ); ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/sns-examples-sending-sms.md
7f2f5c86d160-1
console.error(err, err.stack); } ); ``` To run the example, type the following at the command line\. ``` node sns_listnumbersoptedout.js ``` This example code can be found [here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/sns/sns_listnumbersoptedout.js)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/sns-examples-sending-sms.md
2f7b999a846b-0
In this example, use a Node\.js module to send an SMS message to a phone number\. Create a Node\.js module with the file name `sns_publishsms.js`\. Configure the SDK as previously shown\. Create an object containing the `Message` and `PhoneNumber` parameters\. When you send an SMS message, specify the phone number using the E\.164 format\. E\.164 is a standard for the phone number structure used for international telecommunication\. Phone numbers that follow this format can have a maximum of 15 digits, and they are prefixed with the plus character \(\+\) and the country code\. For example, a US phone number in E\.164 format would appear as \+1001XXX5550100\. This example sets the `PhoneNumber` parameter to specify the phone number to send the message\. Pass the object to the `publish` method of the `AWS.SNS` client class\. To call the `publish` method, create a promise for invoking an Amazon SNS service object, passing the parameters object\. Then handle the `response` in the promise callback\. ``` // Load the AWS SDK for Node.js var AWS = require('aws-sdk'); // Set region AWS.config.update({region: 'REGION'}); // Create publish parameters var params = { Message: 'TEXT_MESSAGE', /* required */ PhoneNumber: 'E.164_PHONE_NUMBER',
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/sns-examples-sending-sms.md
2f7b999a846b-1
Message: 'TEXT_MESSAGE', /* required */ PhoneNumber: 'E.164_PHONE_NUMBER', }; // Create promise and SNS service object var publishTextPromise = new AWS.SNS({apiVersion: '2010-03-31'}).publish(params).promise(); // Handle promise's fulfilled/rejected states publishTextPromise.then( function(data) { console.log("MessageID is " + data.MessageId); }).catch( function(err) { console.error(err, err.stack); }); ``` To run the example, type the following at the command line\. ``` node sns_publishsms.js ``` This example code can be found [here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/sns/sns_publishsms.js)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/sns-examples-sending-sms.md
d54b01dd1ffc-0
Making requests to AWS service clients is straightforward\. **To send a request:** 1. Initialize a client object with the desired configuration, such as a specific AWS Region\. 1. \(Optional\) Create a request JSON object with the values for the request, such as the name of a specific Amazon S3 bucket\. You can examine the parameters for the request by looking at the API reference topic for the interface with the name associated with the client method\. For example, if you use the *AbcCommand* client method, the request interface is *AbcInput*\. 1. Initialize a service command, optionally, with the request object as input\. 1. Call `send` on the client with the command object as input\. For example, to list your Amazon DynamoDB tables in `us-west-2`, you can do it with async/await\. ``` (async function() { const DDB = require('@aws-sdk/client-dynamodb') const dbClient = new DDB.DynamoDBClient({ region: 'us-west-2' }) const command = new DDB.ListTablesCommand({}) try { const results = await dbClient.send(command) console.log(results.TableNames.join('\n')) } catch (err) { console.error(err) } })()
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/the-request-object.md
d54b01dd1ffc-1
} catch (err) { console.error(err) } })() ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/the-request-object.md
708194ebb892-0
![\[JavaScript code example that applies to Node.js execution\]](http://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/images/nodeicon.png) **This Node\.js code example shows:** + How to set up an Amazon S3 bucket as a static web host\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-static-web-host.md
ad078078bf01-0
In this example, a series of Node\.js modules are used to configure any of your buckets to act as a static web host\. The Node\.js modules use the SDK for JavaScript to configure a selected Amazon S3 bucket using these methods of the Amazon S3 client class: + [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#getBucketWebsite-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#getBucketWebsite-property) + [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#putBucketWebsite-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#putBucketWebsite-property) + [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#deleteBucketWebsite-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#deleteBucketWebsite-property)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-static-web-host.md
ad078078bf01-1
For more information about using an Amazon S3 bucket as a static web host, see [Hosting a Static Website on Amazon S3](https://docs.aws.amazon.com/AmazonS3/latest/dev/WebsiteHosting.html) in the *Amazon Simple Storage Service Developer Guide*\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-static-web-host.md
566fb0b0fc5f-0
To set up and run this example, you must first complete these tasks: + Install Node\.js\. For more information about installing Node\.js, see the [Node\.js website](https://nodejs.org)\. + Create a shared configurations file with your user credentials\. For more information about providing a shared credentials file, see [Loading Credentials in Node\.js from the Shared Credentials File](loading-node-credentials-shared.md)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-static-web-host.md
22bf35a3f20a-0
Configure the SDK for JavaScript by creating a global configuration object then setting the Region for your code\. In this example, the Region is set to `us-west-2`\. ``` // Load the SDK for JavaScript var AWS = require('aws-sdk'); // Set the Region AWS.config.update({region: 'us-west-2'}); ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-static-web-host.md
83a7aad895fc-0
Create a Node\.js module with the file name `s3_getbucketwebsite.js`\. The module takes a single command\-line argument that specifies the bucket whose website configuration you want\. Configure the SDK as previously shown\. Create an `AWS.S3` service object\. Create a function that retrieves the current bucket website configuration for the bucket selected in the bucket list\. The only parameter you need to pass is the name of the selected bucket when calling the `getBucketWebsite` method\. If the bucket currently has a website configuration, that configuration is returned by Amazon S3 in the `data` parameter passed to the callback function\. If the selected bucket has no website configuration, that information is returned to the callback function in the `err` parameter\. ``` // Load the AWS SDK for Node.js var AWS = require('aws-sdk'); // Set the region AWS.config.update({region: 'REGION'}); // Create S3 service object s3 = new AWS.S3({apiVersion: '2006-03-01'}); var bucketParams = {Bucket: process.argv[2]}; // call S3 to retrieve the website configuration for selected bucket s3.getBucketWebsite(bucketParams, function(err, data) { if (err) { console.log("Error", err);
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-static-web-host.md
83a7aad895fc-1
if (err) { console.log("Error", err); } else if (data) { console.log("Success", data); } }); ``` To run the example, type the following at the command line\. ``` node s3_getbucketwebsite.js BUCKET_NAME ``` This sample code can be found [here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/s3/s3_getbucketwebsite.js)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-static-web-host.md
d13520e53d02-0
Create a Node\.js module with the file name `s3_setbucketwebsite.js`\. Make sure to configure the SDK as previously shown\. Create an `AWS.S3` service object\. Create a function that applies a bucket website configuration\. The configuration allows the selected bucket to serve as a static web host\. Website configurations are specified in JSON\. First, create a JSON object that contains all the values to specify the website configuration, except for the `Key` value that identifies the error document, and the `Suffix` value that identifies the index document\. Insert the values of the text input elements into the JSON object\. Prepare the parameters for the `putBucketWebsite` method, including the name of the bucket and the JSON website configuration\. ``` // Load the AWS SDK for Node.js var AWS = require('aws-sdk'); // Set the region AWS.config.update({region: 'REGION'}); // Create S3 service object s3 = new AWS.S3({apiVersion: '2006-03-01'}); // Create JSON for putBucketWebsite parameters var staticHostParams = { Bucket: '', WebsiteConfiguration: { ErrorDocument: { Key: '' }, IndexDocument: { Suffix: '' },
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-static-web-host.md
d13520e53d02-1
Key: '' }, IndexDocument: { Suffix: '' }, } }; // Insert specified bucket name and index and error documents into params JSON // from command line arguments staticHostParams.Bucket = process.argv[2]; staticHostParams.WebsiteConfiguration.IndexDocument.Suffix = process.argv[3]; staticHostParams.WebsiteConfiguration.ErrorDocument.Key = process.argv[4]; // set the new website configuration on the selected bucket s3.putBucketWebsite(staticHostParams, function(err, data) { if (err) { // display error message console.log("Error", err); } else { // update the displayed website configuration for the selected bucket console.log("Success", data); } }); ``` To run the example, type the following at the command line\. ``` node s3_setbucketwebsite.js BUCKET_NAME INDEX_PAGE ERROR_PAGE ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-static-web-host.md
d13520e53d02-2
``` node s3_setbucketwebsite.js BUCKET_NAME INDEX_PAGE ERROR_PAGE ``` This sample code can be found [here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/s3/s3_setbucketwebsite.js)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-static-web-host.md
fcf59a41e070-0
Create a Node\.js module with the file name `s3_deletebucketwebsite.js`\. Make sure to configure the SDK as previously shown\. Create an `AWS.S3` service object\. Create a function that deletes the website configuration for the selected bucket\. The only parameter you need to pass when calling the `deleteBucketWebsite` method is the name of the selected bucket\. ``` // Load the AWS SDK for Node.js var AWS = require('aws-sdk'); // Set the region AWS.config.update({region: 'REGION'}); // Create S3 service object s3 = new AWS.S3({apiVersion: '2006-03-01'}); var bucketParams = {Bucket: process.argv[2]}; // call S3 to delete website configuration for selected bucket s3.deleteBucketWebsite(bucketParams, function(error, data) { if (error) { console.log("Error", err); } else if (data) { console.log("Success", data); } }); ``` To run the example, type the following at the command line\. ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-static-web-host.md
fcf59a41e070-1
}); ``` To run the example, type the following at the command line\. ``` node s3_deletebucketwebsite.js BUCKET_NAME ``` This sample code can be found [here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/s3/s3_deletebucketwebsite.js)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-static-web-host.md
ee771613a6c1-0
Amazon S3 Glacier is a secure cloud storage service for data archiving and long\-term backup\. The service is optimized for infrequently accessed data where a retrieval time of several hours is suitable\. ![\[Relationship between JavaScript environments, the SDK, and Glacier\]](http://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/images/code-samples-glacier.png) The JavaScript API for Amazon S3 Glacier is exposed through the `AWS.Glacier` client class\. For more information about using the Glacier client class, see [Class: AWS\.Glacier](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Glacier.html) in the API reference\. **Topics** + [Creating a Glacier Vault](glacier-example-creating-a-vault.md) + [Uploading an Archive to Glacier](glacier-example-uploadrchive.md) + [Doing a Multipart Upload to Glacier](glacier-example-multipart-upload.md)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/glacier-examples.md
491a57121a0d-0
![\[JavaScript code example that applies to Node.js execution\]](http://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/images/nodeicon.png) **This Node\.js code example shows:** + How to query and scan a DynamoDB table for items\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/dynamodb-example-query-scan.md
328efef2a0fa-0
Querying finds items in a table or a secondary index using only primary key attribute values\. You must provide a partition key name and a value for which to search\. You can also provide a sort key name and value, and use a comparison operator to refine the search results\. Scanning finds items by checking every item in the specified table\. In this example, you use a series of Node\.js modules to identify one or more items you want to retrieve from a DynamoDB table\. The code uses the SDK for JavaScript to query and scan tables using these methods of the DynamoDB client class: + [query](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB.html#query-property) + [scan](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB.html#scan-property)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/dynamodb-example-query-scan.md
6b00de89a714-0
To set up and run this example, first complete these tasks: + Install Node\.js\. For more information, see the [Node\.js website](https://nodejs.org)\. + Create a shared configurations file with your user credentials\. For more information about providing a shared credentials file, see [Loading Credentials in Node\.js from the Shared Credentials File](loading-node-credentials-shared.md)\. + Create a DynamoDB table whose items you can access\. For more information about creating a DynamoDB table, see [Creating and Using Tables in DynamoDB](dynamodb-examples-using-tables.md)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/dynamodb-example-query-scan.md
7ce1ce6b3729-0
This example queries a table that contains episode information about a video series, returning the episode titles and subtitles of second season episodes past episode 9 that contain a specified phrase in their subtitle\. Create a Node\.js module with the file name `ddb_query.js`\. Be sure to configure the SDK as previously shown\. To access DynamoDB, create an `AWS.DynamoDB` service object\. Create a JSON object containing the parameters needed to query the table, which in this example includes the table name, the `ExpressionAttributeValues` needed by the query, a `KeyConditionExpression` that uses those values to define which items the query returns, and the names of attribute values to return for each item\. Call the `query` method of the DynamoDB service object\. ``` // Load the AWS SDK for Node.js var AWS = require('aws-sdk'); // Set the region AWS.config.update({region: 'REGION'}); // Create DynamoDB service object var ddb = new AWS.DynamoDB({apiVersion: '2012-08-10'}); var params = { ExpressionAttributeValues: { ':s': {N: '2'}, ':e' : {N: '09'}, ':topic' : {S: 'PHRASE'} },
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/dynamodb-example-query-scan.md
7ce1ce6b3729-1
':e' : {N: '09'}, ':topic' : {S: 'PHRASE'} }, KeyConditionExpression: 'Season = :s and Episode > :e', ProjectionExpression: 'Episode, Title, Subtitle', FilterExpression: 'contains (Subtitle, :topic)', TableName: 'EPISODES_TABLE' }; ddb.query(params, function(err, data) { if (err) { console.log("Error", err); } else { //console.log("Success", data.Items); data.Items.forEach(function(element, index, array) { console.log(element.Title.S + " (" + element.Subtitle.S + ")"); }); } }); ``` To run the example, type the following at the command line\. ``` node ddb_query.js ``` This example code can be found [here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/dynamodb/ddb_query.js)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/dynamodb-example-query-scan.md
e35ccf45b5c7-0
Create a Node\.js module with the file name `ddb_scan.js`\. Be sure to configure the SDK as previously shown\. To access DynamoDB, create an `AWS.DynamoDB` service object\. Create a JSON object containing the parameters needed to scan the table for items, which in this example includes the name of the table, the list of attribute values to return for each matching item, and an expression to filter the result set to find items containing a specified phrase\. Call the `scan` method of the DynamoDB service object\. ``` // Load the AWS SDK for Node.js var AWS = require('aws-sdk'); // Set the region AWS.config.update({region: 'REGION'}); // Create DynamoDB service object var ddb = new AWS.DynamoDB({apiVersion: '2012-08-10'}); var params = { ExpressionAttributeValues: { ':s': {N: '2'}, ':e' : {N: '09'}, ':topic' : {S: 'PHRASE'} }, ProjectionExpression: 'Episode, Title, Subtitle', FilterExpression: 'contains (Subtitle, :topic)', TableName: 'EPISODES_TABLE' }; ddb.scan(params, function(err, data) {
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/dynamodb-example-query-scan.md
e35ccf45b5c7-1
TableName: 'EPISODES_TABLE' }; ddb.scan(params, function(err, data) { if (err) { console.log("Error", err); } else { //console.log("Success", data.Items); data.Items.forEach(function(element, index, array) { console.log(element.Title.S + " (" + element.Subtitle.S + ")"); }); } }); ``` To run the example, type the following at the command line\. ``` node ddb_scan.js ``` This example code can be found [here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/dynamodb/ddb_scan.js)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/dynamodb-example-query-scan.md