id
stringlengths 14
16
| text
stringlengths 1
2.43k
| source
stringlengths 99
229
|
---|---|---|
c4d28168a5a6-1 | `node s3-bucket-setup.js BUCKET_NAME`
The bucket name must be globally unique\. If the command succeeds, the script displays the URL of the new bucket\. Make a note of this URL because you'll use it later\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/using-lambda-s3-setup.md |
65cc714f1faa-0 | The setup script runs the following code\. It takes the command\-line argument that is passed in and uses it to specify the bucket name and the parameter that makes the bucket publicly readable\. It then sets up the parameters used to enable the bucket to act as a static website host\.
```
// Load the AWS SDK for Node.js
var AWS = require('aws-sdk');
// Load credentials and set Region from JSON file
AWS.config.loadFromPath('./config.json');
// Create S3 service object
s3 = new AWS.S3({apiVersion: '2006-03-01'});
// Create params JSON for S3.createBucket
var bucketParams = {
Bucket : process.argv[2],
ACL : 'public-read'
};
// Create params JSON for S3.setBucketWebsite
var staticHostParams = {
Bucket: process.argv[2],
WebsiteConfiguration: {
ErrorDocument: {
Key: 'error.html'
},
IndexDocument: {
Suffix: 'index.html'
},
}
};
// Call S3 to create the bucket | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/using-lambda-s3-setup.md |
65cc714f1faa-1 | Suffix: 'index.html'
},
}
};
// Call S3 to create the bucket
s3.createBucket(bucketParams, function(err, data) {
if (err) {
console.log("Error", err);
} else {
console.log("Bucket URL is ", data.Location);
// Set the new policy on the newly created bucket
s3.putBucketWebsite(staticHostParams, function(err, data) {
if (err) {
// Display error message
console.log("Error", err);
} else {
// Update the displayed policy for the selected bucket
console.log("Success", data);
}
});
}
});
```
Click **next** to continue the tutorial\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/using-lambda-s3-setup.md |
e84e1625d921-0 | The SDK for JavaScript supports all modern web browsers, including these minimum versions\.
****
| Browser | Version |
| --- | --- |
| Google Chrome | 49\.0\+ |
| Mozilla Firefox | 45\.0\+ |
| Opera | 36\.0\+ |
| Microsoft Edge | 12\.0\+ |
| Windows Internet Explorer | N/A |
| Apple Safari | 9\.0\+ |
| Android Browser | 76\.0\+ |
| UC Browser | 12\.12\+ |
| Samsung Internet | 5\.0\+ |
**Note**
Frameworks such as AWS 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/browsers-supported.md |
2427276a23bb-0 | If you can't directly connect to the internet, the SDK for JavaScript supports use of HTTP or HTTPS proxies through a third\-party HTTP agent\.
To find a third\-party HTTP agent, search for "HTTP proxy" at [npm](https://www.npmjs.com/)\.
To install a third\-party HTTP agent proxy, type the following at the command line, where *PROXY* is the name of the `npm` package\.
```
npm install PROXY --save
```
To use a proxy in your application, use the `httpOptions` property, as shown in the following example for a DynamoDB client\.
```
const proxy = require('proxy-agent')
const NodeHttpHandler = require("@aws-sdk/node-http-handler")
const dynamodbClient = new DynamoDBClient({
requestHandler: new NodeHttpHandler({
httpAgent: new Agent({proxy: proxy('http://internal.proxy.com')})
})
})
```
\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/node-configuring-proxies.md |
f3305537f5b6-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 upload an archive to Amazon S3 Glacier using the `uploadArchive` method of the Glacier service object\.
The following example uploads a single `Buffer` object as an entire archive using the `uploadArchive` method of the Glacier service object\.
The example assumes you've already created a vault named `YOUR_VAULT_NAME`\. The SDK automatically computes the tree hash checksum for the data uploaded, though you can override it by passing your own checksum parameter: | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/glacier-example-uploadrchive.md |
7ae496f9a1b6-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/glacier-example-uploadrchive.md |
96a46ba5ce46-0 | ```
// Load the SDK for JavaScript
var AWS = require('aws-sdk');
// Set the region
AWS.config.update({region: 'REGION'});
// Create a new service object and buffer
var glacier = new AWS.Glacier({apiVersion: '2012-06-01'}),
buffer = new Buffer(2.5 * 1024 * 1024); // 2.5MB buffer
var params = {vaultName: 'YOUR_VAULT_NAME', body: buffer};
// Call Glacier to upload the archive.
glacier.uploadArchive(params, function(err, data) {
if (err) {
console.log("Error uploading archive!", err);
} else {
console.log("Archive ID", data.archiveId);
}
});
``` | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/glacier-example-uploadrchive.md |
a53cb95b83c0-0 | Here are a few examples of using web federated identity to obtain credentials in browser JavaScript\. These examples must be run from an `http://` or `https://` host scheme to ensure the identity provider can redirect to your application\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/config-web-identity-examples.md |
00ff92ea3e0b-0 | The following code shows how to use Login with Amazon as an identity provider\.
```
<a href="#" id="login">
<img border="0" alt="Login with Amazon"
src="https://images-na.ssl-images-amazon.com/images/G/01/lwa/btnLWA_gold_156x32.png"
width="156" height="32" />
</a>
<div id="amazon-root"></div>
<script type="text/javascript">
var s3 = null;
var clientId = 'amzn1.application-oa2-client.1234567890abcdef'; // client ID
var roleArn = 'arn:aws:iam::AWS_ACCOUNT_ID:role/WEB_IDENTITY_ROLE_NAME';
window.onAmazonLoginReady = function() {
amazon.Login.setClientId(clientId); // set client ID
document.getElementById('login').onclick = function() {
amazon.Login.authorize({scope: 'profile'}, function(response) {
if (!response.error) { // logged in
credentials = new AWS.WebIdentityCredentials({
RoleArn: roleArn, | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/config-web-identity-examples.md |
00ff92ea3e0b-1 | credentials = new AWS.WebIdentityCredentials({
RoleArn: roleArn,
ProviderId: 'www.amazon.com',
WebIdentityToken: response.access_token
});
s3 = new AWS.S3({ credentials: credentials });
console.log('You are now logged in.');
} else {
console.log('There was a problem logging you in.');
}
});
};
};
(function(d) {
var a = d.createElement('script'); a.type = 'text/javascript';
a.async = true; a.id = 'amazon-login-sdk';
a.src = 'https://api-cdn.amazon.com/sdk/login1.js';
d.getElementById('amazon-root').appendChild(a);
})(document);
</script>
``` | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/config-web-identity-examples.md |
d8551586ff54-0 | The following code shows how to use Facebook Login as an identity provider\.
```
<button id="login">Login</button>
<div id="fb-root"></div>
<script type="text/javascript">
var s3 = null;
var appId = '1234567890'; // Facebook app ID
var roleArn = 'arn:aws:iam::AWS_ACCOUNT_ID:role/WEB_IDENTITY_ROLE_NAME';
window.fbAsyncInit = function() {
var s3 = null;
// init the FB JS SDK
FB.init({appId: appId});
document.getElementById('login').onclick = function() {
FB.login(function (response) {
if (response.authResponse) { // logged in
credentials = new AWS.WebIdentityCredentials({
RoleArn: roleArn,
ProviderId: 'graph.facebook.com',
WebIdentityToken: response.authResponse.accessToken
});
s3 = S3.S3Client({ credentials: credentials })
console.log('You are now logged in.');
} else { | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/config-web-identity-examples.md |
d8551586ff54-1 | console.log('You are now logged in.');
} else {
console.log('There was a problem logging you in.');
}
});
};
};
// Load the FB JS SDK asynchronously
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
``` | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/config-web-identity-examples.md |
dfbb60797251-0 | The following code shows how to use Google\+ Sign\-in as an identity provider\. Unlike other providers, the access token used for web identity federation from Google is stored in `response.id_token` instead of `access_token`\.
```
<span
id="login"
class="g-signin"
data-height="short"
data-callback="loginToGoogle"
data-cookiepolicy="single_host_origin"
data-requestvisibleactions="http://schemas.google.com/AddActivity"
data-scope="https://www.googleapis.com/auth/plus.login">
</span>
<script type="text/javascript">
var s3 = null;
var clientID = '1234567890.apps.googleusercontent.com'; // Google client ID
var roleArn = 'arn:aws:iam::AWS_ACCOUNT_ID:role/WEB_IDENTITY_ROLE_NAME';
document.getElementById('login').setAttribute('data-clientid', clientID);
function loginToGoogle(response) {
if (!response.error) {
credentials = new AWS.WebIdentityCredentials({
RoleArn: roleArn, | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/config-web-identity-examples.md |
dfbb60797251-1 | credentials = new AWS.WebIdentityCredentials({
RoleArn: roleArn,
WebIdentityToken: response.id_token
});
s3 = new AWS.S3({ credentials: Credentials })
console.log('You are now logged in.');
} else {
console.log('There was a problem logging you in.');
}
}
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/client:plusone.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
</script>
``` | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/config-web-identity-examples.md |
9db12dc55ee5-0 | AWS Identity and Access Management \(IAM\) is a web service that enables Amazon Web Services \(AWS\) customers to manage users and user permissions in AWS\. The service is targeted at organizations with multiple users or systems in the cloud that use AWS products\. With IAM, you can centrally manage users, security credentials such as access keys, and permissions that control which AWS resources users can access\.
![\[Relationship between JavaScript environments, the SDK, and IAM\]](http://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/images/code-samples-iam.png)
The JavaScript API for IAM is exposed through the `AWS.IAM` client class\. For more information about using the IAM client class, see [Class: AWS\.IAM](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/IAM.html) in the API reference\.
**Topics**
+ [Managing IAM Users](iam-examples-managing-users.md)
+ [Working with IAM Policies](iam-examples-policies.md)
+ [Managing IAM Access Keys](iam-examples-managing-access-keys.md)
+ [Working with IAM Server Certificates](iam-examples-server-certificates.md)
+ [Managing IAM Account Aliases](iam-examples-account-aliases.md) | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/iam-examples.md |
9eacd90fecb4-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 create an Amazon EC2 instance from a public Amazon Machine Image \(AMI\)\.
+ How to create and assign tags to the new Amazon EC2 instance\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/ec2-example-creating-an-instance.md |
7798c3c9137d-0 | In this example, you use a Node\.js module to create an Amazon EC2 instance and assign both a key pair and tags to it\. The code uses the SDK for JavaScript to create and tag an instance by using these methods of the Amazon EC2 client class:
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/EC2.html#runInstances-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/EC2.html#runInstances-property)
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/EC2.html#createTags-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/EC2.html#createTags-property) | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/ec2-example-creating-an-instance.md |
ff5eabc63323-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 key pair\. For details, see [Working with Amazon EC2 Key Pairs](ec2-example-key-pairs.md)\. You use the name of the key pair in this example\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/ec2-example-creating-an-instance.md |
2d1cffd76e6e-0 | Create a Node\.js module with the file name `ec2_createinstances.js`\. Be sure to configure the SDK as previously shown\.
Create an object to pass the parameters for the `runInstances` method of the `AWS.EC2` client class, including the name of the key pair to assign and the ID of the AMI to run\. To call the `runInstances` method, create a promise for invoking an Amazon EC2 service object, passing the parameters\. Then handle the response in the promise callback\.
The code next adds a `Name` tag to a new instance, which the Amazon EC2 console recognizes and displays in the **Name** field of the instance list\. You can add up to 50 tags to an instance, all of which can be added in a single call to the `createTags` method\.
```
// Load the AWS SDK for Node.js
var AWS = require('aws-sdk');
// Load credentials and set region from JSON file
AWS.config.update({region: 'REGION'});
// Create EC2 service object
var ec2 = new AWS.EC2({apiVersion: '2016-11-15'});
// AMI is amzn-ami-2011.09.1.x86_64-ebs
var instanceParams = {
ImageId: 'AMI_ID',
InstanceType: 't2.micro', | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/ec2-example-creating-an-instance.md |
2d1cffd76e6e-1 | var instanceParams = {
ImageId: 'AMI_ID',
InstanceType: 't2.micro',
KeyName: 'KEY_PAIR_NAME',
MinCount: 1,
MaxCount: 1
};
// Create a promise on an EC2 service object
var instancePromise = new AWS.EC2({apiVersion: '2016-11-15'}).runInstances(instanceParams).promise();
// Handle promise's fulfilled/rejected states
instancePromise.then(
function(data) {
console.log(data);
var instanceId = data.Instances[0].InstanceId;
console.log("Created instance", instanceId);
// Add tags to the instance
tagParams = {Resources: [instanceId], Tags: [
{
Key: 'Name',
Value: 'SDK Sample'
}
]};
// Create a promise on an EC2 service object
var tagPromise = new AWS.EC2({apiVersion: '2016-11-15'}).createTags(tagParams).promise();
// Handle promise's fulfilled/rejected states
tagPromise.then(
function(data) {
console.log("Instance tagged");
}).catch( | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/ec2-example-creating-an-instance.md |
2d1cffd76e6e-2 | tagPromise.then(
function(data) {
console.log("Instance tagged");
}).catch(
function(err) {
console.error(err, err.stack);
});
}).catch(
function(err) {
console.error(err, err.stack);
});
```
To run the example, type the following at the command line\.
```
node ec2_createinstances.js
```
This example code can be found [here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/ec2/ec2_createinstances.js)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/ec2-example-creating-an-instance.md |
10a5781edd15-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 configure the cross\-origin resource sharing \(CORS\) permissions for a bucket\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-configuring-buckets.md |
9b17560fc4b5-0 | In this example, a series of Node\.js modules are used to list your Amazon S3 buckets and to configure CORS and bucket logging\. 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#getBucketCors-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#getBucketCors-property)
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#putBucketCors-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#putBucketCors-property)
For more information about using CORS configuration with an Amazon S3 bucket, see [Cross\-Origin Resource Sharing \(CORS\)](https://docs.aws.amazon.com/AmazonS3/latest/dev/cors.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-configuring-buckets.md |
4817a641211d-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-configuring-buckets.md |
bca035d84b75-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-configuring-buckets.md |
b592f1750e5b-0 | Create a Node\.js module with the file name `s3_getcors.js`\. The module will take a single command\-line argument to specify the bucket whose CORS configuration you want\. Make sure to configure the SDK as previously shown\. Create an `AWS.S3` service object\.
The only parameter you need to pass is the name of the selected bucket when calling the `getBucketCors` method\. If the bucket currently has a CORS configuration, that configuration is returned by Amazon S3 as the `CORSRules` property of the `data` parameter passed to the callback function\.
If the selected bucket has no CORS configuration, that information is returned to the callback function in the `error` 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'});
// Set the parameters for S3.getBucketCors
var bucketParams = {Bucket: process.argv[2]};
// call S3 to retrieve CORS configuration for selected bucket
s3.getBucketCors(bucketParams, function(err, data) {
if (err) { | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-configuring-buckets.md |
b592f1750e5b-1 | s3.getBucketCors(bucketParams, function(err, data) {
if (err) {
console.log("Error", err);
} else if (data) {
console.log("Success", JSON.stringify(data.CORSRules));
}
});
```
To run the example, type the following at the command line\.
```
node s3_getcors.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_getcors.js)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-configuring-buckets.md |
0c6682aef32d-0 | Create a Node\.js module with the file name `s3_setcors.js`\. The module takes multiple command\-line arguments, the first of which specifies the bucket whose CORS configuration you want to set\. Additional arguments enumerate the HTTP methods \(POST, GET, PUT, PATCH, DELETE, POST\) you want to allow for the bucket\. Configure the SDK as previously shown\.
Create an `AWS.S3` service object\. Next create a JSON object to hold the values for the CORS configuration as required by the `putBucketCors` method of the `AWS.S3` service object\. Specify `"Authorization"` for the `AllowedHeaders` value and `"*"` for the `AllowedOrigins` value\. Set the value of `AllowedMethods` as empty array initially\.
Specify the allowed methods as command line parameters to the Node\.js module, adding each of the methods that match one of the parameters\. Add the resulting CORS configuration to the array of configurations contained in the `CORSRules` parameter\. Specify the bucket you want to configure for CORS in the `Bucket` 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'}); | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-configuring-buckets.md |
0c6682aef32d-1 | // Create S3 service object
s3 = new AWS.S3({apiVersion: '2006-03-01'});
// Create initial parameters JSON for putBucketCors
var thisConfig = {
AllowedHeaders:["Authorization"],
AllowedMethods:[],
AllowedOrigins:["*"],
ExposeHeaders:[],
MaxAgeSeconds:3000
};
// Assemble the list of allowed methods based on command line parameters
var allowedMethods = [];
process.argv.forEach(function (val, index, array) {
if (val.toUpperCase() === "POST") {allowedMethods.push("POST")};
if (val.toUpperCase() === "GET") {allowedMethods.push("GET")};
if (val.toUpperCase() === "PUT") {allowedMethods.push("PUT")};
if (val.toUpperCase() === "PATCH") {allowedMethods.push("PATCH")};
if (val.toUpperCase() === "DELETE") {allowedMethods.push("DELETE")};
if (val.toUpperCase() === "HEAD") {allowedMethods.push("HEAD")}; | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-configuring-buckets.md |
0c6682aef32d-2 | if (val.toUpperCase() === "HEAD") {allowedMethods.push("HEAD")};
});
// Copy the array of allowed methods into the config object
thisConfig.AllowedMethods = allowedMethods;
// Create array of configs then add the config object to it
var corsRules = new Array(thisConfig);
// Create CORS params
var corsParams = {Bucket: process.argv[2], CORSConfiguration: {CORSRules: corsRules}};
// set the new CORS configuration on the selected bucket
s3.putBucketCors(corsParams, function(err, data) {
if (err) {
// display error message
console.log("Error", err);
} else {
// update the displayed CORS config for the selected bucket
console.log("Success", data);
}
});
```
To run the example, type the following at the command line including one or more HTTP methods as shown\.
```
node s3_setcors.js BUCKET_NAME get put
``` | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-configuring-buckets.md |
0c6682aef32d-3 | ```
node s3_setcors.js BUCKET_NAME get put
```
This sample code can be found [here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/s3/s3_setcors.js)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-configuring-buckets.md |
09a42fc75d89-0 | Before you use the SDK for JavaScript to invoke web services using the API, you must configure the SDK\. At a minimum, you must configure these settings:
+ The AWS Region in which you will request services\.
+ The *credentials* that authorize your access to SDK resources\.
In addition to these settings, you may also have to configure permissions for your AWS resources\. For example, you can limit access to an Amazon S3 bucket or restrict an Amazon DynamoDB table for read\-only access\.
The topics in this section describe various ways to configure the SDK for JavaScript for Node\.js and JavaScript running in a web browser\.
**Topics**
+ [Setting the AWS Region](setting-region.md)
+ [Specifying Custom Endpoints](specifying-endpoints.md)
+ [Getting Your Credentials](getting-your-credentials.md)
+ [Setting Credentials](setting-credentials.md)
+ [Node\.js Considerations](node-js-considerations.md)
+ [Browser Script Considerations](browser-js-considerations.md)
+ [Bundling Applications with webpack](webpack.md) | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/configuring-the-jssdk.md |
951ddc53f234-0 | The AWS SDK for JavaScript provides access to services that it supports through a collection of client classes\. From these client classes, you create service interface objects, commonly called *service objects*\. Each supported AWS service has one or more client classes that offer low\-level APIs for using service features and resources\. For example, Amazon DynamoDB APIs are available through the `AWS.DynamoDB` class\.
The services exposed through the SDK for JavaScript follow the request\-response pattern to exchange messages with calling applications\. In this pattern, the code invoking a service submits an HTTP/HTTPS request to an endpoint for the service\. The request contains parameters needed to successfully invoke the specific feature being called\. The service that is invoked generates a response that is sent back to the requestor\. The response contains data if the operation was successful or error information if the operation was unsuccessful\.
![\[The AWS request response service pattern.\]](http://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/images/request-response.png)
Invoking an AWS service includes the full request and response lifecycle of an operation on a service object, including any retries that are attempted\. A request contains zero or more properties as JSON parameters\. The response is encapsulated in an object related to the operation, and is returned to the requestor through one of several techniques, such as a callback function or a JavaScript promise\.
**Topics**
+ [Creating and Calling Service Objects](creating-and-calling-service-objects.md) | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/working-with-services.md |
951ddc53f234-1 | **Topics**
+ [Creating and Calling Service Objects](creating-and-calling-service-objects.md)
+ [Calling Services Asychronously](calling-services-asynchronously.md)
+ [Creating Service Client Requests](the-request-object.md)
+ [Handling Service Client Responses](the-response-object.md)
+ [Working with JSON](working-with-json.md) | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/working-with-services.md |
b3a7f9b4f8a3-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 create topics in Amazon SNS to which you can publish notifications\.
+ How to delete topics created in Amazon SNS\.
+ How to get a list of available topics\.
+ How to get and set topic attributes\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/sns-examples-managing-topics.md |
1eaf5fe3253d-0 | In this example, you use a series of Node\.js modules to create, list, and delete Amazon SNS topics, and to handle topic attributes\. The Node\.js modules use the SDK for JavaScript to manage topics using these methods of the `AWS.SNS` client class:
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SNS.html#createTopic-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SNS.html#createTopic-property)
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SNS.html#listTopics-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SNS.html#listTopics-property)
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SNS.html#deleteTopic-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SNS.html#deleteTopic-property) | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/sns-examples-managing-topics.md |
1eaf5fe3253d-1 | + [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SNS.html#getTopicAttributes-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SNS.html#getTopicAttributes-property)
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SNS.html#setTopicAttributes-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SNS.html#setTopicAttributes-property) | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/sns-examples-managing-topics.md |
f4deaf5b53ba-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-managing-topics.md |
bce4cfb63449-0 | In this example, use a Node\.js module to create an Amazon SNS topic\. Create a Node\.js module with the file name `sns_createtopic.js`\. Configure the SDK as previously shown\.
Create an object to pass the `Name` for the new topic to the `createTopic` method of the `AWS.SNS` client class\. To call the `createTopic` method, create a promise for invoking an Amazon SNS service object, passing the parameters object\. Then handle the `response` in the promise callback\. The `data` returned by the promise contains the ARN of the topic\.
```
// 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 createTopicPromise = new AWS.SNS({apiVersion: '2010-03-31'}).createTopic({Name: "TOPIC_NAME"}).promise();
// Handle promise's fulfilled/rejected states
createTopicPromise.then(
function(data) {
console.log("Topic ARN is " + data.TopicArn);
}).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-managing-topics.md |
bce4cfb63449-1 | function(err) {
console.error(err, err.stack);
});
```
To run the example, type the following at the command line\.
```
node sns_createtopic.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_createtopic.js)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/sns-examples-managing-topics.md |
c4490e8e28b3-0 | In this example, use a Node\.js module to list all Amazon SNS topics\. Create a Node\.js module with the file name `sns_listtopics.js`\. Configure the SDK as previously shown\.
Create an empty object to pass to the `listTopics` method of the `AWS.SNS` client class\. To call the `listTopics` method, create a promise for invoking an Amazon SNS service object, passing the parameters object\. Then handle the `response` in the promise callback\. The `data` returned by the promise contains an array of your topic ARNs\.
```
// 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 listTopicsPromise = new AWS.SNS({apiVersion: '2010-03-31'}).listTopics({}).promise();
// Handle promise's fulfilled/rejected states
listTopicsPromise.then(
function(data) {
console.log(data.Topics);
}).catch(
function(err) {
console.error(err, err.stack);
});
```
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/sns-examples-managing-topics.md |
c4490e8e28b3-1 | });
```
To run the example, type the following at the command line\.
```
node sns_listtopics.js
```
This sample code can be found [here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/sns/sns_listtopics.js)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/sns-examples-managing-topics.md |
52b6a2d3270c-0 | In this example, use a Node\.js module to delete an Amazon SNS topic\. Create a Node\.js module with the file name `sns_deletetopic.js`\. Configure the SDK as previously shown\.
Create an object containing the `TopicArn` of the topic to delete to pass to the `deleteTopic` method of the `AWS.SNS` client class\. To call the `deleteTopic` 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 deleteTopicPromise = new AWS.SNS({apiVersion: '2010-03-31'}).deleteTopic({TopicArn: 'TOPIC_ARN'}).promise();
// Handle promise's fulfilled/rejected states
deleteTopicPromise.then(
function(data) {
console.log("Topic Deleted");
}).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-managing-topics.md |
52b6a2d3270c-1 | function(err) {
console.error(err, err.stack);
});
```
To run the example, type the following at the command line\.
```
node sns_deletetopic.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_deletetopic.js)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/sns-examples-managing-topics.md |
a38120bf7400-0 | In this example, use a Node\.js module to retrieve attributes of an Amazon SNS topic\. Create a Node\.js module with the file name `sns_gettopicattributes.js`\. Configure the SDK as previously shown\.
Create an object containing the `TopicArn` of a topic to delete to pass to the `getTopicAttributes` method of the `AWS.SNS` client class\. To call the `getTopicAttributes` 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 getTopicAttribsPromise = new AWS.SNS({apiVersion: '2010-03-31'}).getTopicAttributes({TopicArn: 'TOPIC_ARN'}).promise();
// Handle promise's fulfilled/rejected states
getTopicAttribsPromise.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-managing-topics.md |
a38120bf7400-1 | function(err) {
console.error(err, err.stack);
});
```
To run the example, type the following at the command line\.
```
node sns_gettopicattributes.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_gettopicattributes.js)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/sns-examples-managing-topics.md |
d39928d3de0d-0 | In this example, use a Node\.js module to set the mutable attributes of an Amazon SNS topic\. Create a Node\.js module with the file name `sns_settopicattributes.js`\. Configure the SDK as previously shown\.
Create an object containing the parameters for the attribute update, including the `TopicArn` of the topic whose attributes you want to set, the name of the attribute to set, and the new value for that attribute\. You can set only the `Policy`, `DisplayName`, and `DeliveryPolicy` attributes\. Pass the parameters to the `setTopicAttributes` method of the `AWS.SNS` client class\. To call the `setTopicAttributes` 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 setTopicAttributes parameters
var params = {
AttributeName: 'ATTRIBUTE_NAME', /* required */
TopicArn: 'TOPIC_ARN', /* required */
AttributeValue: 'NEW_ATTRIBUTE_VALUE'
};
// Create promise and SNS service object | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/sns-examples-managing-topics.md |
d39928d3de0d-1 | AttributeValue: 'NEW_ATTRIBUTE_VALUE'
};
// Create promise and SNS service object
var setTopicAttribsPromise = new AWS.SNS({apiVersion: '2010-03-31'}).setTopicAttributes(params).promise();
// Handle promise's fulfilled/rejected states
setTopicAttribsPromise.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_settopicattributes.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_settopicattributes.js)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/sns-examples-managing-topics.md |
402bf2ba574b-0 | Amazon Kinesis is a platform for streaming data on AWS, offering powerful services to load and analyze streaming data, and also providing the ability for you to build custom streaming data applications for specialized needs\.
![\[Relationship between JavaScript environments, the SDK, and Kinesis\]](http://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/images/code-samples-kinesis.png)
The JavaScript API for Kinesis is exposed through the `AWS.Kinesis` client class\. For more information about using the Kinesis client class, see [Class: AWS\.Kinesis](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Kinesis.html) in the API reference\.
**Topics**
+ [Capturing Webpage Scroll Progress with Amazon Kinesis](kinesis-examples-capturing-page-scrolling.md) | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/kinesis-examples.md |
bd5e452fe361-0 | You can keep your AWS credentials data in a shared file used by SDKs and the command line interface\. When the SDK for JavaScript loads, it automatically searches the shared credentials file, which is named "credentials"\. Where you keep the shared credentials file depends on your operating system:
+ The shared credentials file on Linux, Unix, and macOS: `~/.aws/credentials`
+ The shared credentials file on Windows: `C:\Users\USER_NAME\.aws\credentials`
If you do not already have a shared credentials file, see [Getting Your Credentials](getting-your-credentials.md)\. Once you follow those instructions, you should see text similar to the following in the credentials file, where *<YOUR\_ACCESS\_KEY\_ID>* is your access key ID and *<YOUR\_SECRET\_ACCESS\_KEY>* is your secret access key:
```
[default]
aws_access_key_id = <YOUR_ACCESS_KEY_ID>
aws_secret_access_key = <YOUR_SECRET_ACCESS_KEY>
```
For an example showing this file being used, see [Getting Started in Node\.js](getting-started-nodejs.md)\.
The `[default]` section heading specifies a default profile and associated values for credentials\. You can create additional profiles in the same shared configuration file, each with its own credential information\. The following example shows a configuration file with the default profile and two additional profiles:
```
[default] ; default profile | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/loading-node-credentials-shared.md |
bd5e452fe361-1 | ```
[default] ; default profile
aws_access_key_id = <DEFAULT_ACCESS_KEY_ID>
aws_secret_access_key = <DEFAULT_SECRET_ACCESS_KEY>
[personal-account] ; personal account profile
aws_access_key_id = <PERSONAL_ACCESS_KEY_ID>
aws_secret_access_key = <PERSONAL_SECRET_ACCESS_KEY>
[work-account] ; work account profile
aws_access_key_id = <WORK_ACCESS_KEY_ID>
aws_secret_access_key = <WORK_SECRET_ACCESS_KEY>
```
By default, the SDK checks the `AWS_PROFILE` environment variable to determine which profile to use\. If the `AWS_PROFILE` variable is not set in your environment, the SDK uses the credentials for the `[default]` profile\. To use one of the alternate profiles, set or change the value of the `AWS_PROFILE` environment variable\. For example, given the configuration file shown above, to use the credentials from the work account, set the `AWS_PROFILE` environment variable to `work-account` \(as appropriate for your operating system\)\.
**Note**
When setting environment variables, be sure to take appropriate actions afterwards \(according to the needs of your operating system\) to make the variables available in the shell or command environment\.
After setting the environment variable \(if needed\), you can run a file named `script.js` that uses the SDK as follows\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/loading-node-credentials-shared.md |
bd5e452fe361-2 | After setting the environment variable \(if needed\), you can run a file named `script.js` that uses the SDK as follows\.
```
$ node script.js
```
You can also explicitly select the profile used by a client as shown in the following example\.
```
const s3Client = new S3.S3Client({profile: 'work-account'})
``` | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/loading-node-credentials-shared.md |
df3287315377-0 | When you create an AWS account, your account is provided with root credentials\. Those credentials consist of two access keys:
+ Access key ID
+ Secret access key
For more information about your access keys, see [Understanding and Getting Your Security Credentials](https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html) in the *AWS General Reference*\.
Access keys consist of an access key ID and secret access key, which are used to sign programmatic requests that you make to AWS\. If you don't have access keys, you can create them from the AWS Management Console\. As a best practice, do not use the AWS account root user access keys for any task where it's not required\. Instead, [create a new administrator IAM user](https://docs.aws.amazon.com/IAM/latest/UserGuide/getting-started_create-admin-group.html) with access keys for yourself\.
The only time that you can view or download the secret access key is when you create the keys\. You cannot recover them later\. However, you can create new access keys at any time\. You must also have permissions to perform the required IAM actions\. For more information, see [Permissions Required to Access IAM Resources](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_permissions-required.html) in the *IAM User Guide*\.
**To create access keys for an IAM user** | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/getting-your-credentials.md |
df3287315377-1 | **To create access keys for an IAM user**
1. Sign in to the AWS Management Console and open the IAM console at [https://console\.aws\.amazon\.com/iam/](https://console.aws.amazon.com/iam/)\.
1. In the navigation pane, choose **Users**\.
1. Choose the name of the user whose access keys you want to create, and then choose the **Security credentials** tab\.
1. In the **Access keys** section, choose **Create access key**\.
1. To view the new access key pair, choose **Show**\. You will not have access to the secret access key again after this dialog box closes\. Your credentials will look something like this:
+ Access key ID: AKIAIOSFODNN7EXAMPLE
+ Secret access key: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
1. To download the key pair, choose **Download \.csv file**\. Store the keys in a secure location\. You will not have access to the secret access key again after this dialog box closes\.
Keep the keys confidential in order to protect your AWS account and never email them\. Do not share them outside your organization, even if an inquiry appears to come from AWS or Amazon\.com\. No one who legitimately represents Amazon will ever ask you for your secret key\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/getting-your-credentials.md |
df3287315377-2 | 1. After you download the `.csv` file, choose **Close**\. When you create an access key, the key pair is active by default, and you can use the pair right away\.
**Related topics**
+ [What Is IAM?](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html) in the *IAM User Guide*
+ [AWS Security Credentials](https://docs.aws.amazon.com/general/latest/gr/aws-security-credentials.html) in *AWS General Reference* | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/getting-your-credentials.md |
db5ee6f6fa81-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 retrieve the bucket policy of an Amazon S3 bucket\.
+ How to add or update the bucket policy of an Amazon S3 bucket\.
+ How to delete the bucket policy of an Amazon S3 bucket\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-bucket-policies.md |
514f35bafdb5-0 | In this example, a series of Node\.js modules are used to retrieve, set, or delete a bucket policy on an Amazon S3 bucket\. The Node\.js modules use the SDK for JavaScript to configure policy for a selected Amazon S3 bucket using these methods of the Amazon S3 client class:
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#getBucketPolicy-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#getBucketPolicy-property)
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#putBucketPolicy-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#putBucketPolicy-property)
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#deleteBucketPolicy-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#deleteBucketPolicy-property) | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-bucket-policies.md |
514f35bafdb5-1 | For more information about bucket policies for Amazon S3 buckets, see [ Using Bucket Policies and User Policies](https://docs.aws.amazon.com/AmazonS3/latest/dev/using-iam-policies.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-bucket-policies.md |
edbe9abbbaad-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-bucket-policies.md |
ce7ff1998b1d-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-bucket-policies.md |
28f1ba86755c-0 | Create a Node\.js module with the file name `s3_getbucketpolicy.js`\. The module takes a single command\-line argument that specifies the bucket whose policy you want\. Make sure to configure the SDK as previously shown\.
Create an `AWS.S3` service object\. The only parameter you need to pass is the name of the selected bucket when calling the `getBucketPolicy` method\. If the bucket currently has a policy, that policy is returned by Amazon S3 in the `data` parameter passed to the callback function\.
If the selected bucket has no policy, that information is returned to the callback function in the `error` 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 policy for selected bucket
s3.getBucketPolicy(bucketParams, function(err, data) {
if (err) {
console.log("Error", err);
} else if (data) {
console.log("Success", data.Policy); | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-bucket-policies.md |
28f1ba86755c-1 | } else if (data) {
console.log("Success", data.Policy);
}
});
```
To run the example, type the following at the command line\.
```
node s3_getbucketpolicy.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_getbucketpolicy.js)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-bucket-policies.md |
d592a156a791-0 | Create a Node\.js module with the file name `s3_setbucketpolicy.js`\. The module takes a single command\-line argument that specifies the bucket whose policy you want to apply\. Configure the SDK as previously shown\.
Create an `AWS.S3` service object\. Bucket policies are specified in JSON\. First, create a JSON object that contains all of the values to specify the policy except for the `Resource` value that identifies the bucket\.
Format the `Resource` string required by the policy, incorporating the name of the selected bucket\. Insert that string into the JSON object\. Prepare the parameters for the `putBucketPolicy` method, including the name of the bucket and the JSON policy converted to a string value\.
```
// 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 readOnlyAnonUserPolicy = {
Version: "2012-10-17",
Statement: [
{
Sid: "AddPerm",
Effect: "Allow",
Principal: "*",
Action: [
"s3:GetObject"
], | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-bucket-policies.md |
d592a156a791-1 | Principal: "*",
Action: [
"s3:GetObject"
],
Resource: [
""
]
}
]
};
// create selected bucket resource string for bucket policy
var bucketResource = "arn:aws:s3:::" + process.argv[2] + "/*";
readOnlyAnonUserPolicy.Statement[0].Resource[0] = bucketResource;
// convert policy JSON into string and assign into params
var bucketPolicyParams = {Bucket: process.argv[2], Policy: JSON.stringify(readOnlyAnonUserPolicy)};
// set the new policy on the selected bucket
s3.putBucketPolicy(bucketPolicyParams, function(err, data) {
if (err) {
// display error message
console.log("Error", err);
} else {
console.log("Success", data);
}
});
```
To run the example, type the following at the command line\.
```
node s3_setbucketpolicy.js BUCKET_NAME
``` | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-bucket-policies.md |
d592a156a791-2 | ```
node s3_setbucketpolicy.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_setbucketpolicy.js)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-bucket-policies.md |
774126699be1-0 | Create a Node\.js module with the file name `s3_deletebucketpolicy.js`\. The module takes a single command\-line argument that specifies the bucket whose policy you want to delete\. Configure the SDK as previously shown\.
Create an `AWS.S3` service object\. The only parameter you need to pass when calling the `deleteBucketPolicy` 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 policy for selected bucket
s3.deleteBucketPolicy(bucketParams, function(err, data) {
if (err) {
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-bucket-policies.md |
774126699be1-1 | });
```
To run the example, type the following at the command line\.
```
node s3_deletebucketpolicy.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_deletebucketpolicy.js)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-bucket-policies.md |
a2f0c8e06a81-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 photo album in an Amazon Simple Storage Service \(Amazon S3\) bucket and allow unauthenticated users to view the photos\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-photos-view.md |
e82cc08b6e35-0 | In this example, a simple HTML page provides a browser\-based application for viewing the photos in a photo album\. The photo album is in an Amazon S3 bucket into which photos are uploaded\.
![\[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\. The script uses the [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#listObjects-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#listObjects-property) method of the Amazon S3 client class to enable you to view the photo albums\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-photos-view.md |
c294ed98b5bd-0 | To set up and run this example, first complete these tasks\.
**Note**
In this example, you must use the same AWS Region for both the Amazon S3 bucket and the Amazon Cognito identity pool\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-photos-view.md |
abd72d1d8cfb-0 | In the [Amazon S3 console](https://console.aws.amazon.com/s3/), create an Amazon S3 bucket where you can store albums and photos\. For more information about using the console to create an S3 bucket, 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*\.
As you create the S3 bucket, be sure to do the following:
+ Make note of the bucket name so you can use it in a subsequent prerequisite task, Configure Role Permissions\.
+ Choose an AWS Region to create the bucket in\. This must be the same Region that you'll use to create an Amazon Cognito identity pool in a subsequent prerequisite task, Create an Identity Pool\.
+ In the **Create Bucket** wizard, on the **Public access settings\.\.\.** page, in the **Manage public access control lists \(ACLs\)** group, clear these boxes: **Block new public ACLs and uploading public objects** and **Remove public access granted through public ACLs**\.
For information about how to check and configure bucket permissions, see [Setting Bucket and Object Access Permissions](https://docs.aws.amazon.com/AmazonS3/latest/user-guide/set-permissions.html) in the *Amazon Simple Storage Service Console User Guide*\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-photos-view.md |
36395b39de36-0 | In the [Amazon Cognito console](https://console.aws.amazon.com/cognito/), create an Amazon Cognito identity pool, as described in [Step 1: Create an Amazon Cognito Identity Pool](getting-started-browser.md#getting-started-browser-create-identity-pool) of the *Getting Started in a Browser Script* topic\.
As you create the identity pool:
+ Make note of the identity pool name, as well as the role name for the **unauthenticated** identity\.
+ On the **Sample Code** page, select "JavaScript" from the **Platform** list\. Then copy or write down the sample code\.
**Note**
You must choose "JavaScript" from the **Platform** list for your code to work\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-photos-view.md |
c363bbad2288-0 | To allow viewing of albums and photos, you have to add permissions to an IAM role of the identity pool that you just created\. Start by creating a policy as follows\.
1. Open the [IAM console](https://console.aws.amazon.com/iam/)\.
1. In the navigation pane on the left, choose **Policies**, and then choose the **Create policy** button\.
1. On the **JSON** tab, enter the following JSON definition, but replace *BUCKET\_NAME* with the name of the bucket\.
```
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::BUCKET_NAME"
]
}
]
}
```
1. Choose the **Review policy** button, name the policy and provide a description \(if you want\), and then choose the **Create policy** button\.
Be sure to make note of the name so that you can find it and attach it to the IAM role later\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-photos-view.md |
c363bbad2288-1 | Be sure to make note of the name so that you can find it and attach it to the IAM role later\.
After the policy is created, navigate back to the [IAM console](https://console.aws.amazon.com/iam/)\. Find the IAM role for the **unauthenticated** identity that Amazon Cognito created in the previous prerequisite task, Create an Identity Pool\. You use the policy you just created to add permissions to this identity\.
Although the workflow for this task is generally the same as [Step 2: Add a Policy to the Created IAM Role](getting-started-browser.md#getting-started-browser-iam-role) of the *Getting Started in a Browser Script* topic, there are a few differences to note:
+ Use the new policy that you just created, not a policy for Amazon Polly\.
+ On the **Attach Permissions** page, to quickly find the new policy, open the **Filter policies** list and choose **Customer managed**\.
For additional 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*\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-photos-view.md |
9591bf88e7e3-0 | Before the browser script can access the Amazon S3 bucket, you have to 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>GET</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-photos-view.md |
bbd510f64d85-0 | Because this example only allows users to view the photos that are already in the bucket, you need to create some albums in the bucket and upload photos to them\.
**Note**
For this example, the file names of the photo files must start with a single underscore \("\_"\)\. This character is important later for filtering\. In addition, be sure to respect the copyrights of the owners of the photos\.
1. In the [Amazon S3 console](https://console.aws.amazon.com/s3/), open the bucket that you created earlier\.
1. On the **Overview** tab, choose the **Create folder** button to create folders\. For this example, name the folders "album1", "album2", and "album3"\.
1. For **album1** and then **album2**, select the folder and then upload photos to it as follows:
1. Choose the **Upload** button\.
1. Drag or choose the photo files you want to use, and then choose **Next**\.
1. Under **Manage public permissions**, choose **Grant public read access to this object\(s\)**\.
1. Choose the **Upload** button \(in the lower\-left corner\)\.
1. Leave **album3** empty\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-photos-view.md |
568ae9665088-0 | The HTML for the photo\-viewing application consists of a `<div>` element in which the browser script creates the viewing 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\.
For this example, the file is named `PhotoViewer.js`, and is located in the same folder as the HTML file\. To find the current SDK\_VERSION\_NUMBER, see the API Reference for the SDK for JavaScript at [https://docs\.aws\.amazon\.com/AWSJavaScriptSDK/latest/index\.html](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/)\.
```
<!DOCTYPE html>
<html>
<head>
<!-- **DO THIS**: -->
<!-- Replace SDK_VERSION_NUMBER with the current SDK version number -->
<script src="https://sdk.amazonaws.com/js/aws-sdk-SDK_VERSION_NUMBER.js"></script>
<script src="./PhotoViewer.js"></script>
<script>listAlbums();</script>
</head>
<body>
<h1>Photo Album Viewer</h1>
<div id="viewer" /> | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-photos-view.md |
568ae9665088-1 | <body>
<h1>Photo Album Viewer</h1>
<div id="viewer" />
</body>
</html>
``` | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-photos-view.md |
99a6d156ea52-0 | Obtain the credentials you need to configure the SDK by calling the `CognitoIdentityCredentials` method\. You need to provide the Amazon Cognito identity pool ID\. Then create an `AWS.S3` service object\.
```
// **DO THIS**:
// Replace BUCKET_NAME with the bucket name.
//
var albumBucketName = 'BUCKET_NAME';
// **DO THIS**:
// Replace this block of code with the sample code located at:
// Cognito -- Manage Identity Pools -- [identity_pool_name] -- Sample Code -- JavaScript
//
// Initialize the Amazon Cognito credentials provider
AWS.config.region = 'REGION'; // Region
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: 'IDENTITY_POOL_ID',
});
// Create a new service object
var s3 = new AWS.S3({
apiVersion: '2006-03-01',
params: {Bucket: albumBucketName}
});
// A utility function to create HTML.
function getHtml(template) {
return template.join('\n');
}
``` | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-photos-view.md |
99a6d156ea52-1 | function getHtml(template) {
return template.join('\n');
}
```
The rest of the code in this example defines the following functions to gather and present information about the albums and photos in the bucket\.
+ `listAlbums`
+ `viewAlbum` | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-photos-view.md |
374ec96dbdcc-0 | To list all of the existing albums in the bucket, the application's `listAlbums` function calls the `listObjects` method of the `AWS.S3` service object\. The function uses the `CommonPrefixes` property so that the call returns only objects that are used as albums \(that is, the folders\)\.
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 on the webpage\.
```
// List the photo albums that exist in the bucket.
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>',
'<button style="margin:5px;" onclick="viewAlbum(\'' + albumName + '\')">',
albumName,
'</button>',
'</li>'
]);
}); | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-photos-view.md |
374ec96dbdcc-1 | albumName,
'</button>',
'</li>'
]);
});
var message = albums.length ?
getHtml([
'<p>Click on an album name to view it.</p>',
]) :
'<p>You do not have any albums. Please Create album.';
var htmlTemplate = [
'<h2>Albums</h2>',
message,
'<ul>',
getHtml(albums),
'</ul>',
]
document.getElementById('viewer').innerHTML = getHtml(htmlTemplate);
}
});
}
``` | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-photos-view.md |
19af14624707-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 \(the photos\) in the album\.
The rest of the function takes the list of objects that are in the album and generates the HTML needed to display the photos on the webpage\.
```
// Show the photos that exist in an album.
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>',
'<div>', | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-photos-view.md |
19af14624707-1 | return getHtml([
'<span>',
'<div>',
'<br/>',
'<img style="width:128px;height:128px;" src="' + photoUrl + '"/>',
'</div>',
'<div>',
'<span>',
photoKey.replace(albumPhotosKey, ''),
'</span>',
'</div>',
'</span>',
]);
});
var message = photos.length ?
'<p>The following photos are present.</p>' :
'<p>There are no photos in this album.</p>';
var htmlTemplate = [
'<div>',
'<button onclick="listAlbums()">',
'Back To Albums',
'</button>',
'</div>',
'<h2>',
'Album: ' + albumName,
'</h2>',
message,
'<div>',
getHtml(photos),
'</div>',
'<h2>', | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-photos-view.md |
19af14624707-2 | getHtml(photos),
'</div>',
'<h2>',
'End of Album: ' + albumName,
'</h2>',
'<div>',
'<button onclick="listAlbums()">',
'Back To Albums',
'</button>',
'</div>',
]
document.getElementById('viewer').innerHTML = getHtml(htmlTemplate);
});
}
``` | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-photos-view.md |
36b65c44fd86-0 | The following topics show examples of how the AWS SDK for JavaScript can be used to interact with Amazon S3 buckets using Node\.js\.
**Topics**
+ [Creating and Using Amazon S3 Buckets](s3-example-creating-buckets.md)
+ [Configuring Amazon S3 Buckets](s3-example-configuring-buckets.md)
+ [Managing Amazon S3 Bucket Access Permissions](s3-example-access-permissions.md)
+ [Working with Amazon S3 Bucket Policies](s3-example-bucket-policies.md)
+ [Using an Amazon S3 Bucket as a Static Web Host](s3-example-static-web-host.md) | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-node-examples.md |
e1cae5767932-0 | -----
*****Copyright © 2019 Amazon Web Services, Inc. and/or its affiliates. All rights reserved.*****
-----
Amazon's trademarks and trade dress may not be used in
connection with any product or service that is not Amazon's,
in any manner that is likely to cause confusion among customers,
or in any manner that disparages or discredits Amazon. All other
trademarks not owned by Amazon are the property of their respective
owners, who may or may not be affiliated with, connected to, or
sponsored by Amazon.
----- | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/index.md |
a5ea9442f08f-0 | + [What Is the AWS SDK for JavaScript?](welcome.md)
+ [Getting Started with the AWS SDK for JavaScript](getting-started.md)
+ [Getting Started in a Browser Script](getting-started-browser.md)
+ [Getting Started in Node.js](getting-started-nodejs.md)
+ [Setting Up the SDK for JavaScript](setting-up.md)
+ [Prerequisites](jssdk-prerequisites.md)
+ [Setting Up an AWS Node.js Environment](setting-up-node.md)
+ [Supported Web Browsers](browsers-supported.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)
+ [Configuring the SDK for JavaScript](configuring-the-jssdk.md)
+ [Setting the AWS Region](setting-region.md)
+ [Specifying Custom Endpoints](specifying-endpoints.md)
+ [Getting Your Credentials](getting-your-credentials.md)
+ [Setting Credentials](setting-credentials.md)
+ [Setting Credentials in Node.js](setting-credentials-node.md) | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/index.md |
a5ea9442f08f-1 | + [Setting Credentials](setting-credentials.md)
+ [Setting Credentials in Node.js](setting-credentials-node.md)
+ [Loading Credentials in Node.js from IAM Roles for Amazon EC2](loading-node-credentials-iam.md)
+ [Loading Credentials for a Node.js Lambda Function](loading-node-credentials-lambda.md)
+ [Loading Credentials in Node.js from the Shared Credentials File](loading-node-credentials-shared.md)
+ [Loading Credentials in Node.js from Environment Variables](loading-node-credentials-environment.md)
+ [Loading Credentials in Node.js using a Configured Credential Process](loading-node-credentials-configured-credential-process.md)
+ [Setting Credentials in a Web Browser](setting-credentials-browser.md)
+ [Using Amazon Cognito Identity to Authenticate Users](loading-browser-credentials-cognito.md)
+ [Using Web Federated Identity to Authenticate Users](loading-browser-credentials-federated-id.md)
+ [Web Federated Identity Examples](config-web-identity-examples.md)
+ [Node.js Considerations](node-js-considerations.md)
+ [Configuring maxSockets in Node.js](node-configuring-maxsockets.md)
+ [Reusing Connections with Keep-Alive in Node.js](node-reusing-connections.md) | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/index.md |
a5ea9442f08f-2 | + [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)
+ [Browser Script Considerations](browser-js-considerations.md)
+ [Bundling Applications with webpack](webpack.md)
+ [Working with Services in the SDK for JavaScript](working-with-services.md)
+ [Creating and Calling Service Objects](creating-and-calling-service-objects.md)
+ [Calling Services Asychronously](calling-services-asynchronously.md)
+ [Managing Asychronous Calls](making-asynchronous-calls.md)
+ [Using async/await](using-async-await.md)
+ [Using JavaScript Promises](using-promises.md)
+ [Using an Anonymous Callback Function](using-a-callback-function.md)
+ [Creating Service Client Requests](the-request-object.md)
+ [Handling Service Client Responses](the-response-object.md)
+ [Working with JSON](working-with-json.md)
+ [SDK for JavaScript Code Examples](sdk-code-samples.md)
+ [Amazon CloudWatch Examples](cloudwatch-examples.md) | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/index.md |
a5ea9442f08f-3 | + [Amazon CloudWatch Examples](cloudwatch-examples.md)
+ [Creating Alarms in Amazon CloudWatch](cloudwatch-examples-creating-alarms.md)
+ [Using Alarm Actions in Amazon CloudWatch](cloudwatch-examples-using-alarm-actions.md)
+ [Getting Metrics from Amazon CloudWatch](cloudwatch-examples-getting-metrics.md)
+ [Sending Events to Amazon CloudWatch Events](cloudwatch-examples-sending-events.md)
+ [Using Subscription Filters in Amazon CloudWatch Logs](cloudwatch-examples-subscriptions.md)
+ [Amazon DynamoDB Examples](dynamodb-examples.md)
+ [Creating and Using Tables in DynamoDB](dynamodb-examples-using-tables.md)
+ [Reading and Writing a Single Item in DynamoDB](dynamodb-example-table-read-write.md)
+ [Reading and Writing Items in Batch in DynamoDB](dynamodb-example-table-read-write-batch.md)
+ [Querying and Scanning a DynamoDB Table](dynamodb-example-query-scan.md)
+ [Using the DynamoDB Document Client](dynamodb-example-document-client.md)
+ [Amazon EC2 Examples](ec2-examples.md)
+ [Creating an Amazon EC2 Instance](ec2-example-creating-an-instance.md)
+ [Managing Amazon EC2 Instances](ec2-example-managing-instances.md) | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/index.md |
a5ea9442f08f-4 | + [Managing Amazon EC2 Instances](ec2-example-managing-instances.md)
+ [Working with Amazon EC2 Key Pairs](ec2-example-key-pairs.md)
+ [Using Regions and Availability Zones with Amazon EC2](ec2-example-regions-availability-zones.md)
+ [Working with Security Groups in Amazon EC2](ec2-example-security-groups.md)
+ [Using Elastic IP Addresses in Amazon EC2](ec2-example-elastic-ip-addresses.md)
+ [AWS Elemental MediaConvert Examples](emc-examples.md)
+ [Getting Your Account-Specific Endpoint for MediaConvert](emc-examples-getendpoint.md)
+ [Creating and Managing Transcoding Jobs in MediaConvert](emc-examples-jobs.md)
+ [Using Job Templates in MediaConvert](emc-examples-templates.md)
+ [Amazon S3 Glacier Examples](glacier-examples.md)
+ [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)
+ [AWS Identity and Access Management Examples](iam-examples.md)
+ [Managing IAM Users](iam-examples-managing-users.md) | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/index.md |
a5ea9442f08f-5 | + [Managing IAM Users](iam-examples-managing-users.md)
+ [Working with IAM Policies](iam-examples-policies.md)
+ [Managing IAM Access Keys](iam-examples-managing-access-keys.md)
+ [Working with IAM Server Certificates](iam-examples-server-certificates.md)
+ [Managing IAM Account Aliases](iam-examples-account-aliases.md)
+ [Amazon Kinesis Example](kinesis-examples.md)
+ [Capturing Webpage Scroll Progress with Amazon Kinesis](kinesis-examples-capturing-page-scrolling.md)
+ [Capturing Webpage Scroll Progress Code](kinesis-examples-capturing-page-scrolling-full.md)
+ [AWS Lambda Examples](lambda-examples.md)
+ [Amazon S3 Examples](s3-examples.md)
+ [Amazon S3 Browser Examples](s3-browser-examples.md)
+ [Viewing Photos in an Amazon S3 Bucket from a Browser](s3-example-photos-view.md)
+ [Viewing Photos in an Amazon S3 Bucket: Full Code](s3-example-photos-view-full.md)
+ [Uploading Photos to Amazon S3 from a Browser](s3-example-photo-album.md)
+ [Uploading Photos to Amazon S3: Full Code](s3-example-photo-album-full.md) | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/index.md |
a5ea9442f08f-6 | + [Uploading Photos to Amazon S3: Full Code](s3-example-photo-album-full.md)
+ [Amazon S3 Node.js Examples](s3-node-examples.md)
+ [Creating and Using Amazon S3 Buckets](s3-example-creating-buckets.md)
+ [Configuring Amazon S3 Buckets](s3-example-configuring-buckets.md)
+ [Managing Amazon S3 Bucket Access Permissions](s3-example-access-permissions.md)
+ [Working with Amazon S3 Bucket Policies](s3-example-bucket-policies.md)
+ [Using an Amazon S3 Bucket as a Static Web Host](s3-example-static-web-host.md)
+ [Amazon Simple Email Service Examples](ses-examples.md)
+ [Managing Amazon SES Identities](ses-examples-managing-identities.md)
+ [Working with Email Templates in Amazon SES](ses-examples-creating-template.md)
+ [Sending Email Using Amazon SES](ses-examples-sending-email.md)
+ [Using IP Address Filters for Email Receipt in Amazon SES](ses-examples-ip-filters.md)
+ [Using Receipt Rules in Amazon SES](ses-examples-receipt-rules.md)
+ [Amazon Simple Notification Service Examples](sns-examples.md)
+ [Managing Topics in Amazon SNS](sns-examples-managing-topics.md) | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/index.md |
a5ea9442f08f-7 | + [Managing Topics in Amazon SNS](sns-examples-managing-topics.md)
+ [Publishing Messages in Amazon SNS](sns-examples-publishing-messages.md)
+ [Managing Subscriptions in Amazon SNS](sns-examples-subscribing-unubscribing-topics.md)
+ [Sending SMS Messages with Amazon SNS](sns-examples-sending-sms.md)
+ [Amazon SQS Examples](sqs-examples.md)
+ [Using Queues in Amazon SQS](sqs-examples-using-queues.md)
+ [Sending and Receiving Messages in Amazon SQS](sqs-examples-send-receive-messages.md)
+ [Managing Visibility Timeout in Amazon SQS](sqs-examples-managing-visibility-timeout.md)
+ [Enabling Long Polling in Amazon SQS](sqs-examples-enable-long-polling.md)
+ [Using Dead Letter Queues in Amazon SQS](sqs-examples-dead-letter-queues.md)
+ [Tutorials for the AWS SDK for JavaScript](tutorials.md)
+ [Tutorial: Setting Up Node.js on an Amazon EC2 Instance](setting-up-node-on-ec2-instance.md)
+ [Tutorial: Creating and Using Lambda Functions](using-lambda-functions.md)
+ [Create an Amazon S3 Bucket Configured as a Static Website](using-lambda-s3-setup.md) | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/index.md |
a5ea9442f08f-8 | + [Create an Amazon S3 Bucket Configured as a Static Website](using-lambda-s3-setup.md)
+ [Prepare the Browser Script](using-lambda-browser-script.md)
+ [Create a Lambda Execution Role in IAM](using-lambda-iam-role-setup.md)
+ [Create and Populate a DynamoDB Table](using-lambda-ddb-setup.md)
+ [Prepare and Create the Lambda Function](using-lambda-function-prep.md)
+ [Run the Lambda Function](running-lambda-function.md)
+ [Security for this AWS Product or Service](security.md)
+ [Data Protection in this AWS Product or Service](data-protection.md)
+ [Identity and Access Management for this AWS Product or Service](security-iam.md)
+ [Compliance Validation for this AWS Product or Service](compliance-validation.md)
+ [Resilience for this AWS Product or Service](disaster-recovery-resiliency.md)
+ [Infrastructure Security for this AWS Product or Service](infrastructure-security.md)
+ [Document History for AWS SDK for JavaScript Version 3](doc-history.md) | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/index.md |
5eaf2b824d01-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 retrieve a list of published CloudWatch metrics\.
+ How to publish data points to CloudWatch metrics\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/cloudwatch-examples-getting-metrics.md |
56f280e916e8-0 | Metrics are data about the performance of your systems\. You can enable detailed monitoring of some resources, such as your Amazon EC2 instances, or your own application metrics\.
In this example, a series of Node\.js modules are used to get metrics from CloudWatch and to send events to Amazon CloudWatch Events\. The Node\.js modules use the SDK for JavaScript to get metrics from CloudWatch using these methods of the `CloudWatch` client class:
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CloudWatch.html#listMetrics-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CloudWatch.html#listMetrics-property)
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CloudWatch.html#putMetricData-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CloudWatch.html#putMetricData-property)
For more information about CloudWatch metrics, see [Using Amazon CloudWatch Metrics](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/working_with_metrics.html) in the *Amazon CloudWatch User Guide*\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/cloudwatch-examples-getting-metrics.md |
711dbbe53e59-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/cloudwatch-examples-getting-metrics.md |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.