id
stringlengths 14
16
| text
stringlengths 1
2.43k
| source
stringlengths 99
229
|
---|---|---|
f1ccac97949e-0 | Create a Node\.js module with the file name `cw_listmetrics.js`\. Be sure to configure the SDK as previously shown\. To access CloudWatch, create an `AWS.CloudWatch` service object\. Create a JSON object containing the parameters needed to list metrics within the `AWS/Logs` namespace\. Call the `listMetrics` method to list the `IncomingLogEvents` metric\.
```
// Load the AWS SDK for Node.js
var AWS = require('aws-sdk');
// Set the region
AWS.config.update({region: 'REGION'});
// Create CloudWatch service object
var cw = new AWS.CloudWatch({apiVersion: '2010-08-01'});
var params = {
Dimensions: [
{
Name: 'LogGroupName', /* required */
},
],
MetricName: 'IncomingLogEvents',
Namespace: 'AWS/Logs'
};
cw.listMetrics(params, function(err, data) {
if (err) {
console.log("Error", err);
} else {
console.log("Metrics", JSON.stringify(data.Metrics));
}
});
``` | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/cloudwatch-examples-getting-metrics.md |
f1ccac97949e-1 | }
});
```
To run the example, type the following at the command line\.
```
node cw_listmetrics.js
```
This example code can be found [here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/cloudwatch/cw_listmetrics.js)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/cloudwatch-examples-getting-metrics.md |
2c4e197b4c24-0 | Create a Node\.js module with the file name `cw_putmetricdata.js`\. Be sure to configure the SDK as previously shown\. To access CloudWatch, create an `AWS.CloudWatch` service object\. Create a JSON object containing the parameters needed to submit a data point for the `PAGES_VISITED` custom metric\. Call the `putMetricData` method\.
```
// Load the AWS SDK for Node.js
var AWS = require('aws-sdk');
// Set the region
AWS.config.update({region: 'REGION'});
// Create CloudWatch service object
var cw = new AWS.CloudWatch({apiVersion: '2010-08-01'});
// Create parameters JSON for putMetricData
var params = {
MetricData: [
{
MetricName: 'PAGES_VISITED',
Dimensions: [
{
Name: 'UNIQUE_PAGES',
Value: 'URLS'
},
],
Unit: 'None',
Value: 1.0
},
],
Namespace: 'SITE/TRAFFIC'
};
cw.putMetricData(params, function(err, data) {
if (err) { | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/cloudwatch-examples-getting-metrics.md |
2c4e197b4c24-1 | };
cw.putMetricData(params, function(err, data) {
if (err) {
console.log("Error", err);
} else {
console.log("Success", JSON.stringify(data));
}
});
```
To run the example, type the following at the command line\.
```
node cw_putmetricdata.js
```
This example code can be found [here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/cloudwatch/cw_putmetricdata.js)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/cloudwatch-examples-getting-metrics.md |
2da544d899b8-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 change the state of your Amazon EC2 instances automatically based on a CloudWatch alarm\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/cloudwatch-examples-using-alarm-actions.md |
51be097f5621-0 | Using alarm actions, you can create alarms that automatically stop, terminate, reboot, or recover your Amazon EC2 instances\. You can use the stop or terminate actions when you no longer need an instance to be running\. You can use the reboot and recover actions to automatically reboot those instances\.
In this example, a series of Node\.js modules are used to define an alarm action in CloudWatch that triggers the reboot of an Amazon EC2 instance\. The Node\.js modules use the SDK for JavaScript to manage Amazon EC2 instances using these methods of the `CloudWatch` client class:
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CloudWatch.html#enableAlarmActions-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CloudWatch.html#enableAlarmActions-property)
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CloudWatch.html#disableAlarmActions-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CloudWatch.html#disableAlarmActions-property)
For more information about CloudWatch alarm actions, see [Create Alarms to Stop, Terminate, Reboot, or Recover an Instance](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/UsingAlarmActions.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-using-alarm-actions.md |
2a4cd8ca8366-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 shared credentials file, see [Loading Credentials in Node\.js from the Shared Credentials File](loading-node-credentials-shared.md)\.
+ Create an IAM role whose policy grants permission to describe, reboot, stop, or terminate an Amazon EC2 instance\. 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 the following role policy when creating the IAM role\.
```
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"cloudwatch:Describe*",
"ec2:Describe*",
"ec2:RebootInstances",
"ec2:StopInstances*",
"ec2:TerminateInstances"
],
"Resource": [
"*"
]
} | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/cloudwatch-examples-using-alarm-actions.md |
2a4cd8ca8366-1 | ],
"Resource": [
"*"
]
}
]
}
``` | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/cloudwatch-examples-using-alarm-actions.md |
73f49b4563e2-0 | Configure the SDK for JavaScript by creating a global configuration object then setting the AWS 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/cloudwatch-examples-using-alarm-actions.md |
b22ba14be1fe-0 | Create a Node\.js module with the file name `cw_enablealarmactions.js`\. Be sure to configure the SDK as previously shown\. To access CloudWatch, create an `AWS.CloudWatch` service object\.
Create a JSON object to hold the parameters for creating an alarm, specifying `ActionsEnabled` as `true` and an array of ARNs for the actions the alarm will trigger\. Call the `putMetricAlarm` method of the `AWS.CloudWatch` service object, which creates the alarm if it does not exist or updates it if the alarm does exist\.
In the callback function for the `putMetricAlarm`, upon successful completion create a JSON object containing the name of the CloudWatch alarm\. Call the `enableAlarmActions` method to enable the alarm action\.
```
// Load the AWS SDK for Node.js
var AWS = require('aws-sdk');
// Set the region
AWS.config.update({region: 'REGION'});
// Create CloudWatch service object
var cw = new AWS.CloudWatch({apiVersion: '2010-08-01'});
var params = {
AlarmName: 'Web_Server_CPU_Utilization',
ComparisonOperator: 'GreaterThanThreshold',
EvaluationPeriods: 1,
MetricName: 'CPUUtilization',
Namespace: 'AWS/EC2',
Period: 60, | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/cloudwatch-examples-using-alarm-actions.md |
b22ba14be1fe-1 | MetricName: 'CPUUtilization',
Namespace: 'AWS/EC2',
Period: 60,
Statistic: 'Average',
Threshold: 70.0,
ActionsEnabled: true,
AlarmActions: ['ACTION_ARN'],
AlarmDescription: 'Alarm when server CPU exceeds 70%',
Dimensions: [
{
Name: 'InstanceId',
Value: 'INSTANCE_ID'
},
],
Unit: 'Percent'
};
cw.putMetricAlarm(params, function(err, data) {
if (err) {
console.log("Error", err);
} else {
console.log("Alarm action added", data);
var paramsEnableAlarmAction = {
AlarmNames: [params.AlarmName]
};
cw.enableAlarmActions(paramsEnableAlarmAction, function(err, data) {
if (err) {
console.log("Error", err);
} else {
console.log("Alarm action enabled", 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/cloudwatch-examples-using-alarm-actions.md |
b22ba14be1fe-2 | }
});
```
To run the example, type the following at the command line\.
```
node cw_enablealarmactions.js
```
This example code can be found [here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/cloudwatch/cw_enablealarmactions.js)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/cloudwatch-examples-using-alarm-actions.md |
1bd031d446c1-0 | Create a Node\.js module with the file name `cw_disablealarmactions.js`\. Be sure to configure the SDK as previously shown\. To access CloudWatch, create an `AWS.CloudWatch` service object\. Create a JSON object containing the name of the CloudWatch alarm\. Call the `disableAlarmActions` method to disable the actions for this alarm\.
```
// Load the AWS SDK for Node.js
var AWS = require('aws-sdk');
// Set the region
AWS.config.update({region: 'REGION'});
// Create CloudWatch service object
var cw = new AWS.CloudWatch({apiVersion: '2010-08-01'});
cw.disableAlarmActions({AlarmNames: ['Web_Server_CPU_Utilization']}, function(err, data) {
if (err) {
console.log("Error", err);
} else {
console.log("Success", data);
}
});
```
To run the example, type the following at the command line\.
```
node cw_disablealarmactions.js
``` | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/cloudwatch-examples-using-alarm-actions.md |
1bd031d446c1-1 | ```
node cw_disablealarmactions.js
```
This example code can be found [here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/cloudwatch/cw_disablealarmactions.js)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/cloudwatch-examples-using-alarm-actions.md |
4ba8e6c09e54-0 | All requests made through the SDK are asynchronous\. This is important to keep in mind when writing browser scripts\. JavaScript running in a web browser typically has just a single execution thread\. After making an asynchronous call to an AWS service, the browser script continues running and in the process can try to execute code that depends on that asynchronous result before it returns\.
Making asynchronous calls to an AWS service includes managing those calls so your code doesn't try to use data before the data is available\. The topics in this section explain the need to manage asynchronous calls and detail different techniques you can use to manage them\.
Although you can use any of these techniques to manage asynchronous calls, we recommend that you use async/await for all new code\.
async/await
We recommend that you use this technique as it is the default behavior in V3\.
promise
Use this technique in browsers that do not support asynch/await\.
callback
Avoid using callbacks except in very simple cases\. However, you might find it useful for migration scenarios\.
**Topics**
+ [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) | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/calling-services-asynchronously.md |
f2228f4ee3ff-0 | The recommended way to obtain AWS credentials for your browser scripts is to use the Amazon Cognito Identity credentials client, `client-cognito-identity`\. Amazon Cognito enables authentication of users through third\-party identity providers\.
To use Amazon Cognito Identity, you must first create an identity pool in the Amazon Cognito console\. An identity pool represents the group of identities that your application provides to your users\. The identities given to users uniquely identify each user account\. Amazon Cognito identities are not credentials\. They are exchanged for credentials using web identity federation support in AWS Security Token Service \(AWS STS\)\.
Amazon Cognito helps you manage the abstraction of identities across multiple identity providers\. The identity that is loaded is then exchanged for credentials in AWS STS\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/loading-browser-credentials-cognito.md |
d29ba18a788c-0 | If you have not yet created one, create an identity pool to use with your browser scripts in the [Amazon Cognito console](https://console.aws.amazon.com/cognito) before you configure your Amazon Cognito client\. Create and associate both authenticated and unauthenticated IAM roles for your identity pool\.
Unauthenticated users do not have their identity verified, making this role appropriate for guest users of your app or in cases when it doesn't matter if users have their identities verified\. Authenticated users log in to your application through a third\-party identity provider that verifies their identities\. Make sure you scope the permissions of resources appropriately so you don't grant access to them from unauthenticated users\.
After you configure an identity pool, use the Amazon Cognito `CognitoIdentityCredentials` method to create the credentials to authenticate users, as shown in the following example of creating an Amazon S3 client in the `us-west-2` Region for users in the *IDENTITY\_POOL\_ID* identity pool\.
```
const cognitoIdentityClient = new CognitoIdentityClient({
region: "us-west-2",
credentials: () => Promise.resolve({} as any),
signer: {} as any
})
cognitoIdentityClient.middlewareStack.remove("SIGNATURE");
const s3Client = new S3Client({
region: "us-west-2", | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/loading-browser-credentials-cognito.md |
d29ba18a788c-1 | const s3Client = new S3Client({
region: "us-west-2",
credentials: fromCognitoIdentityPool({
client: cognitoIdentityClient,
identityPoolId: 'IDENTITY_POOL_ID'
})
})
```
The optional `Logins` property is a map of identity provider names to the identity tokens for those providers\. How you get the token from your identity provider depends on the provider you use\. For example, if Facebook is one of your identity providers, you might use the `FB.login` function from the [Facebook SDK](https://developers.facebook.com/docs/facebook-login/web) to get an identity provider token\.
```
FB.login(function (response) {
if (response.authResponse) { // logged in
const cognitoIdentityClient = new CognitoIdentityClient({
region: "us-west-2",
credentials: () => Promise.resolve({} as any),
signer: {} as any
})
credentials = fromCognitoIdentityPool({
client: cognitoIdentityClient,
IdentityPoolId: 'IDENTITY_POOL_ID',
Logins: {
'graph.facebook.com': 'response.authResponse.accessToken' | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/loading-browser-credentials-cognito.md |
d29ba18a788c-2 | Logins: {
'graph.facebook.com': 'response.authResponse.accessToken'
})
const s3Client = new s3Client({ credentials: credentials });
console.log('You are now logged in.');
} else {
console.log('There was a problem logging you in.');
}
});
``` | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/loading-browser-credentials-cognito.md |
5403423bd984-0 | The following topics show two examples of how the AWS SDK for JavaScript can be used in the browser to interact with Amazon S3 buckets\.
+ The first shows a simple scenario in which the existing photos in an Amazon S3 bucket can be viewed by any \(unauthenticated\) user\.
+ The second shows a more complex scenario in which users are allowed to perform operations on photos in the bucket such as upload, delete, etc\.
**Topics**
+ [Viewing Photos in an Amazon S3 Bucket from a Browser](s3-example-photos-view.md)
+ [Uploading Photos to Amazon S3 from a Browser](s3-example-photo-album.md) | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-browser-examples.md |
2af54c83c5de-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 verify email addresses and domains used with Amazon SES\.
+ How to assign IAM policy to your Amazon SES identities\.
+ How to list all Amazon SES identities for your AWS account\.
+ How to delete identities used with Amazon SES\.
An Amazon SES *identity* is an email address or domain that Amazon SES uses to send email\. Amazon SES requires you to verify your email identities, confirming that you own them and preventing others from using them\.
For details on how to verify email addresses and domains in Amazon SES, see [Verifying Email Addresses and Domains in Amazon SES](Amazon Simple Email Service Developer Guideverify-addresses-and-domains.html) in the Amazon Simple Email Service Developer Guide\. For information about sending authorization in Amazon SES, see [Overview of Amazon SES Sending Authorization](Amazon Simple Email Service Developer Guidesending-authorization-overview.html)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/ses-examples-managing-identities.md |
6c52f3c8b641-0 | In this example, you use a series of Node\.js modules to verify and manage Amazon SES identities\. The Node\.js modules use the SDK for JavaScript to verify email addresses and domains, using these methods of the `AWS.SES` client class:
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SES.html#listIdentities-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SES.html#listIdentities-property)
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SES.html#deleteIdentity-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SES.html#deleteIdentity-property)
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SES.html#verifyEmailIdentity-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SES.html#verifyEmailIdentity-property) | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/ses-examples-managing-identities.md |
6c52f3c8b641-1 | + [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SES.html#verifyDomainIdentity-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SES.html#verifyDomainIdentity-property) | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/ses-examples-managing-identities.md |
cb913983efdf-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 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/ses-examples-managing-identities.md |
47150e3e0c74-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/ses-examples-managing-identities.md |
5f20df43cba9-0 | In this example, use a Node\.js module to list email addresses and domains to use with Amazon SES\. Create a Node\.js module with the file name `ses_listidentities.js`\. Configure the SDK as previously shown\.
Create an object to pass the `IdentityType` and other parameters for the `listIdentities` method of the `AWS.SES` client class\. To call the `listIdentities` method, create a promise for invoking an Amazon SES service object, passing the parameters object\.
Then handle the `response` in the promise callback\. The `data` returned by the promise contains an array of domain identities as specified by the `IdentityType` parameter\.
```
// Load the AWS SDK for Node.js
var AWS = require('aws-sdk');
// Set region
AWS.config.update({region: 'REGION'});
// Create listIdentities params
var params = {
IdentityType: "Domain",
MaxItems: 10
};
// Create the promise and SES service object
var listIDsPromise = new AWS.SES({apiVersion: '2010-12-01'}).listIdentities(params).promise();
// Handle promise's fulfilled/rejected states
listIDsPromise.then(
function(data) { | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/ses-examples-managing-identities.md |
5f20df43cba9-1 | // Handle promise's fulfilled/rejected states
listIDsPromise.then(
function(data) {
console.log(data.Identities);
}).catch(
function(err) {
console.error(err, err.stack);
});
```
To run the example, type the following at the command line\.
```
node ses_listidentities.js
```
This example code can be found [here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/ses/ses_listidentities.js)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/ses-examples-managing-identities.md |
7c89465d1543-0 | In this example, use a Node\.js module to verify email senders to use with Amazon SES\. Create a Node\.js module with the file name `ses_verifyemailidentity.js`\. Configure the SDK as previously shown\. To access Amazon SES, create an `AWS.SES` service object\.
Create an object to pass the `EmailAddress` parameter for the `verifyEmailIdentity` method of the `AWS.SES` client class\. To call the `verifyEmailIdentity` method, create a promise for invoking an Amazon SES service object, passing the parameters\. 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 SES service object
var verifyEmailPromise = new AWS.SES({apiVersion: '2010-12-01'}).verifyEmailIdentity({EmailAddress: "ADDRESS@DOMAIN.EXT"}).promise();
// Handle promise's fulfilled/rejected states
verifyEmailPromise.then(
function(data) {
console.log("Email verification initiated");
}).catch(
function(err) {
console.error(err, err.stack); | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/ses-examples-managing-identities.md |
7c89465d1543-1 | }).catch(
function(err) {
console.error(err, err.stack);
});
```
To run the example, type the following at the command line\. The domain is added to Amazon SES to be verified\.
```
node ses_verifyemailidentity.js
```
This example code can be found [here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/ses/ses_verifyemailidentity.js)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/ses-examples-managing-identities.md |
6485af849788-0 | In this example, use a Node\.js module to verify email domains to use with Amazon SES\. Create a Node\.js module with the file name `ses_verifydomainidentity.js`\. Configure the SDK as previously shown\.
Create an object to pass the `Domain` parameter for the `verifyDomainIdentity` method of the `AWS.SES` client class\. To call the `verifyDomainIdentity` method, create a promise for invoking an Amazon SES 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 the promise and SES service object
var verifyDomainPromise = new AWS.SES({apiVersion: '2010-12-01'}).verifyDomainIdentity({Domain: "DOMAIN_NAME"}).promise();
// Handle promise's fulfilled/rejected states
verifyDomainPromise.then(
function(data) {
console.log("Verification Token: " + data.VerificationToken);
}).catch(
function(err) {
console.error(err, err.stack);
});
``` | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/ses-examples-managing-identities.md |
6485af849788-1 | function(err) {
console.error(err, err.stack);
});
```
To run the example, type the following at the command line\. The domain is added to Amazon SES to be verified\.
```
node ses_verifydomainidentity.js
```
This example code can be found [here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/ses/ses_verifydomainidentity.js)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/ses-examples-managing-identities.md |
da61d319ef1e-0 | In this example, use a Node\.js module to delete email addresses or domains used with Amazon SES\. Create a Node\.js module with the file name `ses_deleteidentity.js`\. Configure the SDK as previously shown\.
Create an object to pass the `Identity` parameter for the `deleteIdentity` method of the `AWS.SES` client class\. To call the `deleteIdentity` method, create a `request` for invoking an Amazon SES service object, passing the parameters\. 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 the promise and SES service object
var deletePromise = new AWS.SES({apiVersion: '2010-12-01'}).deleteIdentity({Identity: "DOMAIN_NAME"}).promise();
// Handle promise's fulfilled/rejected states
deletePromise.then(
function(data) {
console.log("Identity 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/ses-examples-managing-identities.md |
da61d319ef1e-1 | function(err) {
console.error(err, err.stack);
});
```
To run the example, type the following at the command line\.
```
node ses_deleteidentity.js
```
This example code can be found [here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/ses/ses_deleteidentity.js)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/ses-examples-managing-identities.md |
a0dec1359691-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:**
+ Send a text or HTML email\.
+ Send emails based on an email template\.
+ Send bulk emails based on an email template\.
The Amazon SES API provides two different ways for you to send an email, depending on how much control you want over the composition of the email message: formatted and raw\. For details, see [Sending Formatted Email Using the Amazon SES API](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-email-formatted.html) and [Sending Raw Email Using the Amazon SES API](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-email-raw.html)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/ses-examples-sending-email.md |
2e5269edc761-0 | In this example, you use a series of Node\.js modules to send email in a variety of ways\. The Node\.js modules use the SDK for JavaScript to create and use email templates using these methods of the `AWS.SES` client class:
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SES.html#sendEmail-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SES.html#sendEmail-property)
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SES.html#sendTemplatedEmail-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SES.html#sendTemplatedEmail-property)
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SES.html#sendBulkTemplatedEmail-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SES.html#sendBulkTemplatedEmail-property) | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/ses-examples-sending-email.md |
1c72aa9d6b0d-0 | + 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 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/ses-examples-sending-email.md |
58d7032cfe8c-0 | Amazon SES composes an email message and immediately queues it for sending\. To send email using the `SES.sendEmail` method, your message must meet the following requirements:
+ You must send the message from a verified email address or domain\. If you attempt to send email using a non\-verified address or domain, the operation results in an `"Email address not verified"` error\.
+ If your account is still in the Amazon SES sandbox, you can only send to verified addresses or domains, or to email addresses associated with the Amazon SES Mailbox Simulator\. For more information, see [Verifying Email Addresses and Domains](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/verify-addresses-and-domains.html) in the Amazon Simple Email Service Developer Guide\.
+ The total size of the message, including attachments, must be smaller than 10 MB\.
+ The message must include at least one recipient email address\. The recipient address can be a To: address, a CC: address, or a BCC: address\. If a recipient email address is invalid \(that is, it is not in the format `UserName@[SubDomain.]Domain.TopLevelDomain`\), the entire message is rejected, even if the message contains other recipients that are valid\.
+ The message cannot include more than 50 recipients, across the To:, CC: and BCC: fields\. If you need to send an email message to a larger audience, you can divide your recipient list into groups of 50 or fewer, and then call the `sendEmail` method several times to send the message to each group\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/ses-examples-sending-email.md |
9e28af7e9f6c-0 | In this example, use a Node\.js module to send email with Amazon SES\. Create a Node\.js module with the file name `ses_sendemail.js`\. Configure the SDK as previously shown\.
Create an object to pass the parameter values that define the email to be sent, including sender and receiver addresses, subject, email body in plain text and HTML formats, to the `sendEmail` method of the `AWS.SES` client class\. To call the `sendEmail` method, create a promise for invoking an Amazon SES service object, passing the parameters\. Then handle the `response` in the promise callback\.
```
// Load the AWS SDK for Node.js
var AWS = require('aws-sdk');
// Set the region
AWS.config.update({region: 'REGION'});
// Create sendEmail params
var params = {
Destination: { /* required */
CcAddresses: [
'EMAIL_ADDRESS',
/* more items */
],
ToAddresses: [
'EMAIL_ADDRESS',
/* more items */
]
},
Message: { /* required */
Body: { /* required */
Html: {
Charset: "UTF-8", | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/ses-examples-sending-email.md |
9e28af7e9f6c-1 | Body: { /* required */
Html: {
Charset: "UTF-8",
Data: "HTML_FORMAT_BODY"
},
Text: {
Charset: "UTF-8",
Data: "TEXT_FORMAT_BODY"
}
},
Subject: {
Charset: 'UTF-8',
Data: 'Test email'
}
},
Source: 'SENDER_EMAIL_ADDRESS', /* required */
ReplyToAddresses: [
'EMAIL_ADDRESS',
/* more items */
],
};
// Create the promise and SES service object
var sendPromise = new AWS.SES({apiVersion: '2010-12-01'}).sendEmail(params).promise();
// Handle promise's fulfilled/rejected states
sendPromise.then(
function(data) {
console.log(data.MessageId);
}).catch(
function(err) {
console.error(err, err.stack);
});
```
To run the example, type the following at the command line\. The email is queued for sending by Amazon SES\.
``` | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/ses-examples-sending-email.md |
9e28af7e9f6c-2 | To run the example, type the following at the command line\. The email is queued for sending by Amazon SES\.
```
node ses_sendemail.js
```
This example code can be [found here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/ses/ses_sendemail.js)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/ses-examples-sending-email.md |
ee958bb0d1d7-0 | In this example, use a Node\.js module to send email with Amazon SES\. Create a Node\.js module with the file name `ses_sendtemplatedemail.js`\. Configure the SDK as previously shown\.
Create an object to pass the parameter values that define the email to be sent, including sender and receiver addresses, subject, email body in plain text and HTML formats, to the `sendTemplatedEmail` method of the `AWS.SES` client class\. To call the `sendTemplatedEmail` method, create a promise for invoking an Amazon SES service object, passing the parameters\. Then handle the `response` in the promise callback\.
```
// Load the AWS SDK for Node.js
var AWS = require('aws-sdk');
// Set the region
AWS.config.update({region: 'REGION'});
// Create sendTemplatedEmail params
var params = {
Destination: { /* required */
CcAddresses: [
'EMAIL_ADDRESS',
/* more CC email addresses */
],
ToAddresses: [
'EMAIL_ADDRESS',
/* more To email addresses */
]
},
Source: 'EMAIL_ADDRESS', /* required */
Template: 'TEMPLATE_NAME', /* required */ | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/ses-examples-sending-email.md |
ee958bb0d1d7-1 | },
Source: 'EMAIL_ADDRESS', /* required */
Template: 'TEMPLATE_NAME', /* required */
TemplateData: '{ \"REPLACEMENT_TAG_NAME\":\"REPLACEMENT_VALUE\" }', /* required */
ReplyToAddresses: [
'EMAIL_ADDRESS'
],
};
// Create the promise and SES service object
var sendPromise = new AWS.SES({apiVersion: '2010-12-01'}).sendTemplatedEmail(params).promise();
// Handle promise's fulfilled/rejected states
sendPromise.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\. The email is queued for sending by Amazon SES\.
```
node ses_sendtemplatedemail.js
```
This example code can be found [here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/ses/ses_sendtemplatedemail.js)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/ses-examples-sending-email.md |
56129ac3b576-0 | In this example, use a Node\.js module to send email with Amazon SES\. Create a Node\.js module with the file name `ses_sendbulktemplatedemail.js`\. Configure the SDK as previously shown\.
Create an object to pass the parameter values that define the email to be sent, including sender and receiver addresses, subject, email body in plain text and HTML formats, to the `sendBulkTemplatedEmail` method of the `AWS.SES` client class\. To call the `sendBulkTemplatedEmail` method, create a promise for invoking an Amazon SES service object, passing the parameters\. Then handle the `response` in the promise callback\.
```
// Load the AWS SDK for Node.js
var AWS = require('aws-sdk');
// Set the region
AWS.config.update({region: 'REGION'});
// Create sendBulkTemplatedEmail params
var params = {
Destinations: [ /* required */
{
Destination: { /* required */
CcAddresses: [
'EMAIL_ADDRESS',
/* more items */
],
ToAddresses: [
'EMAIL_ADDRESS',
'EMAIL_ADDRESS'
/* more items */
]
}, | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/ses-examples-sending-email.md |
56129ac3b576-1 | 'EMAIL_ADDRESS',
'EMAIL_ADDRESS'
/* more items */
]
},
ReplacementTemplateData: '{ \"REPLACEMENT_TAG_NAME\":\"REPLACEMENT_VALUE\" }'
},
],
Source: 'EMAIL_ADDRESS', /* required */
Template: 'TEMPLATE_NAME', /* required */
DefaultTemplateData: '{ \"REPLACEMENT_TAG_NAME\":\"REPLACEMENT_VALUE\" }',
ReplyToAddresses: [
'EMAIL_ADDRESS'
]
};
// Create the promise and SES service object
var sendPromise = new AWS.SES({apiVersion: '2010-12-01'}).sendBulkTemplatedEmail(params).promise();
// Handle promise's fulfilled/rejected states
sendPromise.then(
function(data) {
console.log(data);
}).catch(
function(err) {
console.log(err, err.stack);
});
```
To run the example, type the following at the command line\. The email is queued for sending by Amazon SES\.
```
node ses_sendbulktemplatedemail.js
``` | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/ses-examples-sending-email.md |
56129ac3b576-2 | ```
node ses_sendbulktemplatedemail.js
```
This example code can be found [here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/ses/ses_sendbulktemplatedemail.js)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/ses-examples-sending-email.md |
d0bc5c96bca9-0 | AWS uses credentials to identify who is calling services and whether access to the requested resources is allowed\. In AWS, these credentials are typically the access key ID and the secret access key that were created along with your account\.
Whether running in a web browser or in a Node\.js server, your JavaScript code must obtain valid credentials before it can access services through the API\. Credentials can be set globally on the configuration object, using `AWS.Config`, or per service, by passing credentials directly to a service object\.
There are several ways to set credentials that differ between Node\.js and JavaScript in web browsers\. The topics in this section describe how to set credentials in Node\.js or web browsers\. In each case, the options are presented in recommended order\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/setting-credentials.md |
6d160159c639-0 | Properly setting credentials ensures that your application or browser script can access the services and resources needed while minimizing exposure to security issues that may impact mission critical applications or compromise sensitive data\.
An important principle to apply when setting credentials is to always grant the least privilege required for your task\. It's more secure to provide minimal permissions on your resources and add further permissions as needed, rather than provide permissions that exceed the least privilege and, as a result, be required to fix security issues you might discover later\. For example, unless you have a need to read and write individual resources, such as objects in an Amazon S3 bucket or a DynamoDB table, set those permissions to read only\.
For more information on granting the least privilege, see the [Grant Least Privilege](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege) section of the Best Practices topic in the *IAM User Guide*\.
**Warning**
While it is possible to do so, we recommend you not hard code credentials inside an application or browser script\. Hard coding credentials poses a risk of exposing your access key ID and secret access key\.
For more information about how to manage your access keys, see [ Best Practices for Managing AWS Access Keys](https://docs.aws.amazon.com/general/latest/gr/aws-access-keys-best-practices.html) in the AWS General Reference\.
**Topics**
+ [Best Practices for Credentials](#credentials-best-practices)
+ [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/setting-credentials.md |
6d160159c639-1 | + [Setting Credentials in Node\.js](setting-credentials-node.md)
+ [Setting Credentials in a Web Browser](setting-credentials-browser.md) | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/setting-credentials.md |
bfd8774c789f-0 | Amazon Simple Storage Service \(Amazon S3\) is a web service that provides highly scalable cloud storage\. Amazon S3 provides easy to use object storage, with a simple web service interface to store and retrieve any amount of data from anywhere on the web\.
![\[Relationship between JavaScript environments, the SDK, and Amazon S3\]](http://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/images/code-samples-s3.png)
The JavaScript API for Amazon S3 is exposed through the `AWS.S3` client class\. For more information about using the Amazon S3 client class, see [Class: AWS\.S3](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html) in the API reference\.
**Topics**
+ [Amazon S3 Browser Examples](s3-browser-examples.md)
+ [Amazon S3 Node\.js Examples](s3-node-examples.md) | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-examples.md |
a280a6417fa5-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 manage aliases for your AWS account ID\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/iam-examples-account-aliases.md |
1acaa628e381-0 | If you want the URL for your sign\-in page to contain your company name or other friendly identifier instead of your AWS account ID, you can create an alias for your AWS account ID\. If you create an AWS account alias, your sign\-in page URL changes to incorporate the alias\.
In this example, a series of Node\.js modules are used to create and manage IAM account aliases\. The Node\.js modules use the SDK for JavaScript to manage aliases using these methods of the `AWS.IAM` client class:
+ [createAccountAlias](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/IAM.html#createAccountAlias-property)
+ [listAccountAliases](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/IAM.html#listAccountAliases-property)
+ [deleteAccountAlias](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/IAM.html#deleteAccountAlias-property)
For more information about IAM account aliases, see [Your AWS Account ID and Its Alias](https://docs.aws.amazon.com/IAM/latest/UserGuide/console_account-alias.html) in the *IAM User Guide*\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/iam-examples-account-aliases.md |
480cf78c2cef-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/iam-examples-account-aliases.md |
258d5bd39045-0 | Create a Node\.js module with the file name `iam_createaccountalias.js`\. Be sure to configure the SDK as previously shown\. To access IAM, create an `AWS.IAM` service object\. Create a JSON object containing the parameters needed to create an account alias, which includes the alias you want to create\. Call the `createAccountAlias` method of the `AWS.IAM` service object\.
```
// Load the AWS SDK for Node.js
var AWS = require('aws-sdk');
// Set the region
AWS.config.update({region: 'REGION'});
// Create the IAM service object
var iam = new AWS.IAM({apiVersion: '2010-05-08'});
iam.createAccountAlias({AccountAlias: process.argv[2]}, function(err, data) {
if (err) {
console.log("Error", err);
} else {
console.log("Success", data);
}
});
```
To run the example, type the following at the command line\.
```
node iam_createaccountalias.js ALIAS
``` | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/iam-examples-account-aliases.md |
258d5bd39045-1 | ```
node iam_createaccountalias.js ALIAS
```
This example code can be found [here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/iam/iam_createaccountalias.js)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/iam-examples-account-aliases.md |
c78083bacb98-0 | Create a Node\.js module with the file name `iam_listaccountaliases.js`\. Be sure to configure the SDK as previously shown\. To access IAM, create an `AWS.IAM` service object\. Create a JSON object containing the parameters needed to list account aliases, which includes the maximum number of items to return\. Call the `listAccountAliases` method of the `AWS.IAM` service object\.
```
// Load the AWS SDK for Node.js
var AWS = require('aws-sdk');
// Set the region
AWS.config.update({region: 'REGION'});
// Create the IAM service object
var iam = new AWS.IAM({apiVersion: '2010-05-08'});
iam.listAccountAliases({MaxItems: 10}, function(err, data) {
if (err) {
console.log("Error", err);
} else {
console.log("Success", data);
}
});
```
To run the example, type the following at the command line\.
```
node iam_listaccountaliases.js
``` | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/iam-examples-account-aliases.md |
c78083bacb98-1 | ```
node iam_listaccountaliases.js
```
This example code can be found [here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/iam/iam_listaccountaliases.js)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/iam-examples-account-aliases.md |
e9cf0f9ab8d9-0 | Create a Node\.js module with the file name `iam_deleteaccountalias.js`\. Be sure to configure the SDK as previously shown\. To access IAM, create an `AWS.IAM` service object\. Create a JSON object containing the parameters needed to delete an account alias, which includes the alias you want deleted\. Call the `deleteAccountAlias` method of the `AWS.IAM` service object\.
```
// Load the AWS SDK for Node.js
var AWS = require('aws-sdk');
// Set the region
AWS.config.update({region: 'REGION'});
// Create the IAM service object
var iam = new AWS.IAM({apiVersion: '2010-05-08'});
iam.deleteAccountAlias({AccountAlias: process.argv[2]}, function(err, data) {
if (err) {
console.log("Error", err);
} else {
console.log("Success", data);
}
});
```
To run the example, type the following at the command line\.
```
node iam_deleteaccountalias.js ALIAS
``` | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/iam-examples-account-aliases.md |
e9cf0f9ab8d9-1 | ```
node iam_deleteaccountalias.js ALIAS
```
This example code can be found [here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/iam/iam_deleteaccountalias.js)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/iam-examples-account-aliases.md |
04305153ec87-0 | This topic is part of a larger tutorial about using the AWS SDK for JavaScript with AWS Lambda functions\. To start at the beginning of the tutorial, see [Tutorial: Creating and Using Lambda Functions](using-lambda-functions.md)\.
In this task, you will focus on creating IAM role used by the application to execute the Lambda function\.
![\[Create an IAM execution role for Lambda\]](http://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/images/create-iam-role.png)![\[Create an IAM execution role for Lambda\]](http://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/)![\[Create an IAM execution role for Lambda\]](http://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/)
A Lambda function requires an execution role created in IAM that provides the function with the necessary permissions to run\. For more information about the Lambda execution role, see [Manage Permissions: Using an IAM Role \(Execution Role\)](https://docs.aws.amazon.com/lambda/latest/dg/intro-permission-model.html#lambda-intro-execution-role) in the *AWS Lambda Developer Guide*\.
**To create the Lambda execution role in IAM**
1. Open `lambda-role-setup.js` in the `slotassets` directory in a text editor\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/using-lambda-iam-role-setup.md |
04305153ec87-1 | 1. Open `lambda-role-setup.js` in the `slotassets` directory in a text editor\.
1. Find this line of code\.
`RoleName: "ROLE"`
Replace **ROLE** with another name\.
1. Save your changes and close the file\.
1. At the command line, type the following\.
`node lambda-role-setup.js`
1. Make a note of the ARN returned by the script\. You need this value to create the Lambda function\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/using-lambda-iam-role-setup.md |
746edc7092ea-0 | The following code is the setup script that creates the Lambda execution role\. The setup script creates the JSON that defines the trust relationship needed for a Lambda execution role\. It also creates the JSON parameters for attaching the AWSLambdaRole managed policy\. Then it assigns the string version of the JSON to the parameters for the `createRole` method of the IAM service object\.
The `createRole` method automatically URL\-encodes the JSON to create the execution role\. When the new role is successfully created, the script displays its ARN\. Then the script calls the `attachRolePolicy` method of the IAM service object to attach the managed policy\. When the policy is successfully attached, the script displays a confirmation message\.
```
// 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 the IAM service object
var iam = new AWS.IAM({apiVersion: '2010-05-08'});
var myPolicy = {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Action": "sts:AssumeRole" | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/using-lambda-iam-role-setup.md |
746edc7092ea-1 | "Service": "lambda.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
};
var createParams = {
AssumeRolePolicyDocument: JSON.stringify(myPolicy),
RoleName: "ROLE"
};
var policyParams = {
PolicyArn: "arn:aws:iam::policy/service-role/AWSLambdaRole",
RoleName: "ROLE"
};
iam.createRole(createParams, function(err, data) {
if (err) {
console.log(err, err.stack); // an error occurred
} else {
console.log("Role ARN is", data.Role.Arn); // successful response
iam.attachRolePolicy(policyParams , function(err, data) {
if (err) {
console.log(err, err.stack);
} else {
console.log("AWSLambdaRole Policy attached");
}
});
}
});
```
Click **next** to continue the tutorial\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/using-lambda-iam-role-setup.md |
3e729a7f6978-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 IAM users\.
+ How to create and delete users\.
+ How to update a user name\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/iam-examples-managing-users.md |
2e03c707c66c-0 | In this example, a series of Node\.js modules are used to create and manage users in IAM\. The Node\.js modules use the SDK for JavaScript to create, delete, and update users using these methods of the `AWS.IAM` client class:
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/IAM.html#createUser-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/IAM.html#createUser-property)
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/IAM.html#listUsers-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/IAM.html#listUsers-property)
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/IAM.html#updateUser-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/IAM.html#updateUser-property)
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/IAM.html#getUser-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/IAM.html#getUser-property) | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/iam-examples-managing-users.md |
2e03c707c66c-1 | + [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/IAM.html#deleteUser-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/IAM.html#deleteUser-property)
For more information about IAM users, see [IAM Users](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_users.html) in the *IAM User Guide*\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/iam-examples-managing-users.md |
cd910c7455ae-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/iam-examples-managing-users.md |
c4595fac0f70-0 | Create a Node\.js module with the file name `iam_createuser.js`\. Be sure to configure the SDK as previously shown\. To access IAM, create an `AWS.IAM` service object\. Create a JSON object containing the parameters needed, which consists of the user name you want to use for the new user as a command\-line parameter\.
Call the `getUser` method of the `AWS.IAM` service object to see if the user name already exists\. If the user name does not currently exist, call the `createUser` method to create it\. If the name already exists, write a message to that effect to the console\.
```
// Load the AWS SDK for Node.js
var AWS = require('aws-sdk');
// Set the region
AWS.config.update({region: 'REGION'});
// Create the IAM service object
var iam = new AWS.IAM({apiVersion: '2010-05-08'});
var params = {
UserName: process.argv[2]
};
iam.getUser(params, function(err, data) {
if (err && err.code === 'NoSuchEntity') {
iam.createUser(params, 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/iam-examples-managing-users.md |
c4595fac0f70-1 | if (err) {
console.log("Error", err);
} else {
console.log("Success", data);
}
});
} else {
console.log("User " + process.argv[2] + " already exists", data.User.UserId);
}
});
```
To run the example, type the following at the command line\.
```
node iam_createuser.js USER_NAME
```
This example code can be found [here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/iam/iam_createuser.js)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/iam-examples-managing-users.md |
2d0ede06b15d-0 | Create a Node\.js module with the file name `iam_listusers.js`\. Be sure to configure the SDK as previously shown\. To access IAM, create an `AWS.IAM` service object\. Create a JSON object containing the parameters needed to list your users, limiting the number returned by setting the `MaxItems` parameter to 10\. Call the `listUsers` method of the `AWS.IAM` service object\. Write the first user's name and creation date to the console\.
```
// Load the AWS SDK for Node.js
var AWS = require('aws-sdk');
// Set the region
AWS.config.update({region: 'REGION'});
// Create the IAM service object
var iam = new AWS.IAM({apiVersion: '2010-05-08'});
var params = {
MaxItems: 10
};
iam.listUsers(params, function(err, data) {
if (err) {
console.log("Error", err);
} else {
var users = data.Users || [];
users.forEach(function(user) {
console.log("User " + user.UserName + " created", user.CreateDate);
});
}
}); | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/iam-examples-managing-users.md |
2d0ede06b15d-1 | });
}
});
```
To run the example, type the following at the command line\.
```
node iam_listusers.js
```
This example code can be found [here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/iam/iam_listusers.js)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/iam-examples-managing-users.md |
254158ddbe94-0 | Create a Node\.js module with the file name `iam_updateuser.js`\. Be sure to configure the SDK as previously shown\. To access IAM, create an `AWS.IAM` service object\. Create a JSON object containing the parameters needed to list your users, specifying both the current and new user names as command\-line parameters\. Call the `updateUser` method of the `AWS.IAM` service object\.
```
// Load the AWS SDK for Node.js
var AWS = require('aws-sdk');
// Set the region
AWS.config.update({region: 'REGION'});
// Create the IAM service object
var iam = new AWS.IAM({apiVersion: '2010-05-08'});
var params = {
UserName: process.argv[2],
NewUserName: process.argv[3]
};
iam.updateUser(params, function(err, data) {
if (err) {
console.log("Error", err);
} else {
console.log("Success", data);
}
});
```
To run the example, type the following at the command line, specifying the user's current name followed by the new user name\.
``` | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/iam-examples-managing-users.md |
254158ddbe94-1 | To run the example, type the following at the command line, specifying the user's current name followed by the new user name\.
```
node iam_updateuser.js ORIGINAL_USERNAME NEW_USERNAME
```
This example code can be found [here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/iam/iam_updateuser.js)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/iam-examples-managing-users.md |
1e24ed4bc91a-0 | Create a Node\.js module with the file name `iam_deleteuser.js`\. Be sure to configure the SDK as previously shown\. To access IAM, create an `AWS.IAM` service object\. Create a JSON object containing the parameters needed, which consists of the user name you want to delete as a command\-line parameter\.
Call the `getUser` method of the `AWS.IAM` service object to see if the user name already exists\. If the user name does not currently exist, write a message to that effect to the console\. If the user exists, call the `deleteUser` method to delete it\.
```
// Load the AWS SDK for Node.js
var AWS = require('aws-sdk');
// Set the region
AWS.config.update({region: 'REGION'});
// Create the IAM service object
var iam = new AWS.IAM({apiVersion: '2010-05-08'});
var params = {
UserName: process.argv[2]
};
iam.getUser(params, function(err, data) {
if (err && err.code === 'NoSuchEntity') {
console.log("User " + process.argv[2] + " does not exist.");
} else { | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/iam-examples-managing-users.md |
1e24ed4bc91a-1 | console.log("User " + process.argv[2] + " does not exist.");
} else {
iam.deleteUser(params, function(err, data) {
if (err) {
console.log("Error", err);
} else {
console.log("Success", data);
}
});
}
});
```
To run the example, type the following at the command line\.
```
node iam_deleteuser.js USER_NAME
```
This example code can be found [here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/iam/iam_deleteuser.js)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/iam-examples-managing-users.md |
49b43e93db9e-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 specify the account\-specific endpoint to use with MediaConvert\.
+ How to create transcoding jobs in MediaConvert\.
+ How to cancel a transcoding job\.
+ How to retrieve the JSON for a completed transcoding job\.
+ How to retrieve a JSON array for up to 20 of the most recently created jobs\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/emc-examples-jobs.md |
65e509abba38-0 | In this example, you use a Node\.js module to call MediaConvert to create and manage transcoding jobs\. The code uses the SDK for JavaScript to do this by using these methods of the MediaConvert client class:
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/MediaConvert.html#createJob-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/MediaConvert.html#createJob-property)
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/MediaConvert.html#cancelJob-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/MediaConvert.html#cancelJob-property)
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/MediaConvert.html#getJob-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/MediaConvert.html#getJob-property)
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/MediaConvert.html#listJobs-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/MediaConvert.html#listJobs-property) | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/emc-examples-jobs.md |
ef7af7f8ef6e-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 and configure Amazon S3 buckets that provide storage for job input files and output files\. For details, see [Create Storage for Files](https://docs.aws.amazon.com/mediaconvert/latest/ug/set-up-file-locations.html) in the *AWS Elemental MediaConvert User Guide*\.
+ Upload the input video to the Amazon S3 bucket you provisioned for input storage\. For a list of supported input video codecs and containers, see [Supported Input Codecs and Containers](https://docs.aws.amazon.com/mediaconvert/latest/ug/reference-codecs-containers-input.html) in the *AWS Elemental MediaConvert User Guide*\.
+ Create an IAM role that gives MediaConvert access to your input files and the Amazon S3 buckets where your output files are stored\. For details, see [Set Up IAM Permissions](https://docs.aws.amazon.com/mediaconvert/latest/ug/iam-role.html) in the *AWS Elemental MediaConvert User Guide*\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/emc-examples-jobs.md |
b42f6e322cc0-0 | Configure the SDK for JavaScript by creating a global configuration object, and then setting the Region for your code\. In this example, the Region is set to `us-west-2`\. Because MediaConvert uses custom endpoints for each account, you must also configure the `AWS.MediaConvert` client class to use your account\-specific endpoint\. To do this, set the `endpoint` parameter on `AWS.config.mediaconvert`\.
```
// Load the SDK for JavaScript
var AWS = require('aws-sdk');
// Set the Region
AWS.config.update({region: 'us-west-2'});
// Set the custom endpoint for your account
AWS.config.mediaconvert = {endpoint : 'ACCOUNT_ENDPOINT'};
``` | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/emc-examples-jobs.md |
f34de6fc9859-0 | Create a Node\.js module with the file name `emc_createjob.js`\. Be sure to configure the SDK as previously shown\. Create the JSON that defines the transcode job parameters\.
These parameters are quite detailed\. You can use the [AWS Elemental MediaConvert console](https://console.aws.amazon.com/mediaconvert/) to generate the JSON job parameters by choosing your job settings in the console, and then choosing **Show job JSON** at the bottom of the **Job** section\. This example shows the JSON for a simple job\.
```
var params = {
"Queue": "JOB_QUEUE_ARN",
"UserMetadata": {
"Customer": "Amazon"
},
"Role": "IAM_ROLE_ARN",
"Settings": {
"OutputGroups": [
{
"Name": "File Group",
"OutputGroupSettings": {
"Type": "FILE_GROUP_SETTINGS",
"FileGroupSettings": {
"Destination": "s3://OUTPUT_BUCKET_NAME/"
}
},
"Outputs": [
{
"VideoDescription": {
"ScalingBehavior": "DEFAULT",
"TimecodeInsertion": "DISABLED", | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/emc-examples-jobs.md |
f34de6fc9859-1 | "ScalingBehavior": "DEFAULT",
"TimecodeInsertion": "DISABLED",
"AntiAlias": "ENABLED",
"Sharpness": 50,
"CodecSettings": {
"Codec": "H_264",
"H264Settings": {
"InterlaceMode": "PROGRESSIVE",
"NumberReferenceFrames": 3,
"Syntax": "DEFAULT",
"Softness": 0,
"GopClosedCadence": 1,
"GopSize": 90,
"Slices": 1,
"GopBReference": "DISABLED",
"SlowPal": "DISABLED",
"SpatialAdaptiveQuantization": "ENABLED",
"TemporalAdaptiveQuantization": "ENABLED",
"FlickerAdaptiveQuantization": "DISABLED",
"EntropyEncoding": "CABAC",
"Bitrate": 5000000,
"FramerateControl": "SPECIFIED",
"RateControlMode": "CBR",
"CodecProfile": "MAIN",
"Telecine": "NONE",
"MinIInterval": 0,
"AdaptiveQuantization": "HIGH",
"CodecLevel": "AUTO", | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/emc-examples-jobs.md |
f34de6fc9859-2 | "MinIInterval": 0,
"AdaptiveQuantization": "HIGH",
"CodecLevel": "AUTO",
"FieldEncoding": "PAFF",
"SceneChangeDetect": "ENABLED",
"QualityTuningLevel": "SINGLE_PASS",
"FramerateConversionAlgorithm": "DUPLICATE_DROP",
"UnregisteredSeiTimecode": "DISABLED",
"GopSizeUnits": "FRAMES",
"ParControl": "SPECIFIED",
"NumberBFramesBetweenReferenceFrames": 2,
"RepeatPps": "DISABLED",
"FramerateNumerator": 30,
"FramerateDenominator": 1,
"ParNumerator": 1,
"ParDenominator": 1
}
},
"AfdSignaling": "NONE",
"DropFrameTimecode": "ENABLED",
"RespondToAfd": "NONE",
"ColorMetadata": "INSERT"
},
"AudioDescriptions": [
{
"AudioTypeControl": "FOLLOW_INPUT",
"CodecSettings": {
"Codec": "AAC",
"AacSettings": { | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/emc-examples-jobs.md |
f34de6fc9859-3 | "CodecSettings": {
"Codec": "AAC",
"AacSettings": {
"AudioDescriptionBroadcasterMix": "NORMAL",
"RateControlMode": "CBR",
"CodecProfile": "LC",
"CodingMode": "CODING_MODE_2_0",
"RawFormat": "NONE",
"SampleRate": 48000,
"Specification": "MPEG4",
"Bitrate": 64000
}
},
"LanguageCodeControl": "FOLLOW_INPUT",
"AudioSourceName": "Audio Selector 1"
}
],
"ContainerSettings": {
"Container": "MP4",
"Mp4Settings": {
"CslgAtom": "INCLUDE",
"FreeSpaceBox": "EXCLUDE",
"MoovPlacement": "PROGRESSIVE_DOWNLOAD"
}
},
"NameModifier": "_1"
}
]
}
],
"AdAvailOffset": 0,
"Inputs": [
{
"AudioSelectors": {
"Audio Selector 1": { | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/emc-examples-jobs.md |
f34de6fc9859-4 | "Inputs": [
{
"AudioSelectors": {
"Audio Selector 1": {
"Offset": 0,
"DefaultSelection": "NOT_DEFAULT",
"ProgramSelection": 1,
"SelectorType": "TRACK",
"Tracks": [
1
]
}
},
"VideoSelector": {
"ColorSpace": "FOLLOW"
},
"FilterEnable": "AUTO",
"PsiControl": "USE_PSI",
"FilterStrength": 0,
"DeblockFilter": "DISABLED",
"DenoiseFilter": "DISABLED",
"TimecodeSource": "EMBEDDED",
"FileInput": "s3://INPUT_BUCKET_AND_FILE_NAME"
}
],
"TimecodeConfig": {
"Source": "EMBEDDED"
}
}
};
``` | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/emc-examples-jobs.md |
b9e1389fb957-0 | After creating the job parameters JSON, call the `createJob` method by creating a promise for invoking an `AWS.MediaConvert` service object, passing the parameters\. Then handle the response in the promise callback\. The ID of the job created is returned in the response `data`\.
```
// Create a promise on a MediaConvert object
var endpointPromise = new AWS.MediaConvert({apiVersion: '2017-08-29'}).createJob(params).promise();
// Handle promise's fulfilled/rejected status
endpointPromise.then(
function(data) {
console.log("Job created! ", data);
},
function(err) {
console.log("Error", err);
}
);
```
To run the example, type the following at the command line\.
```
node emc_createjob.js
```
This example code can be found [here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/mediaconvert/emc_createjob.js)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/emc-examples-jobs.md |
0d15403e4cf1-0 | Create a Node\.js module with the file name `emc_canceljob.js`\. Be sure to configure the SDK as previously shown\. Create the JSON that includes the ID of the job to cancel\. Then call the `cancelJob` method by creating a promise for invoking an `AWS.MediaConvert` service object, passing the parameters\. Handle the response in the promise callback\.
```
// Load the AWS SDK for Node.js
var AWS = require('aws-sdk');
// Set the Region
AWS.config.update({region: 'us-west-2'});
// Set MediaConvert to customer endpoint
AWS.config.mediaconvert = {endpoint : 'ACCOUNT_ENDPOINT'};
var params = {
Id: 'JOB_ID' /* required */
};
// Create a promise on a MediaConvert object
var endpointPromise = new AWS.MediaConvert({apiVersion: '2017-08-29'}).cancelJob(params).promise();
// Handle promise's fulfilled/rejected status
endpointPromise.then(
function(data) {
console.log("Job " + params.Id + " is canceled");
},
function(err) {
console.log("Error", err); | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/emc-examples-jobs.md |
0d15403e4cf1-1 | },
function(err) {
console.log("Error", err);
}
);
```
To run the example, type the following at the command line\.
```
node ec2_canceljob.js
```
This example code can be found [here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/mediaconvert/emc_canceljob.js)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/emc-examples-jobs.md |
303a01ace1c8-0 | Create a Node\.js module with the file name `emc_listjobs.js`\. Be sure to configure the SDK as previously shown\.
Create the parameters JSON, including values to specify whether to sort the list in `ASCENDING`, or `DESCENDING` order, the ARN of the job queue to check, and the status of jobs to include\. Then call the `listJobs` method by creating a promise for invoking an `AWS.MediaConvert` service object, passing the parameters\. Handle the response in the promise callback\.
```
// Load the AWS SDK for Node.js
var AWS = require('aws-sdk');
// Set the Region
AWS.config.update({region: 'us-west-2'});
// Set the customer endpoint
AWS.config.mediaconvert = {endpoint : 'ACCOUNT_ENDPOINT'};
var params = {
MaxResults: 10,
Order: 'ASCENDING',
Queue: 'QUEUE_ARN',
Status: 'SUBMITTED'
};
// Create a promise on a MediaConvert object
var endpointPromise = new AWS.MediaConvert({apiVersion: '2017-08-29'}).listJobs(params).promise();
// Handle promise's fulfilled/rejected status
endpointPromise.then( | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/emc-examples-jobs.md |
303a01ace1c8-1 | // Handle promise's fulfilled/rejected status
endpointPromise.then(
function(data) {
console.log("Jobs: ", data);
},
function(err) {
console.log("Error", err);
}
);
```
To run the example, type the following at the command line\.
```
node emc_listjobs.js
```
This example code can be found [here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/mediaconvert/emc_listjobs.js)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/emc-examples-jobs.md |
faf119d00efa-0 | This section contains the full HTML and JavaScript code for the example in which photos in an Amazon S3 bucket can be viewed\. See the [parent section](s3-example-photos-view.md) for details and prerequisites\.
The HTML for the example:
```
<!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" />
</body>
</html>
```
This sample code can be found [here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/s3/s3_PhotoViewer.html)\.
The browser script code for the example:
```
// | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-photos-view-full.md |
faf119d00efa-1 | The browser script code for the example:
```
//
// Data constructs and initialization.
//
// **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');
}
//
// Functions
//
// List the photo albums that exist in the bucket. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-photos-view-full.md |
faf119d00efa-2 | }
//
// Functions
//
// 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>'
]);
});
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, | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-photos-view-full.md |
faf119d00efa-3 | var htmlTemplate = [
'<h2>Albums</h2>',
message,
'<ul>',
getHtml(albums),
'</ul>',
]
document.getElementById('viewer').innerHTML = getHtml(htmlTemplate);
}
});
}
// 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>',
'<br/>', | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-photos-view-full.md |
faf119d00efa-4 | 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-full.md |
faf119d00efa-5 | getHtml(photos),
'</div>',
'<h2>',
'End of Album: ' + albumName,
'</h2>',
'<div>',
'<button onclick="listAlbums()">',
'Back To Albums',
'</button>',
'</div>',
]
document.getElementById('viewer').innerHTML = getHtml(htmlTemplate);
});
}
```
This sample code can be found [here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/s3/s3_PhotoViewer.js)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-photos-view-full.md |
66a71b333318-0 | There are several ways to supply your credentials to the SDK from browser scripts\. Some of these are more secure and others afford greater convenience while developing a script\. Here are the ways you can supply your credentials in order of recommendation:
1. Using Amazon Cognito Identity to authenticate users and supply credentials
1. Using web federated identity
1. Hard coded in the script
**Warning**
We do not recommend hard coding your AWS credentials in your scripts\. Hard coding credentials poses a risk of exposing your access key ID and secret access key\.
**Topics**
+ [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) | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/setting-credentials-browser.md |
0df9d3b34736-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 carry out basic tasks in managing server certificates for HTTPS connections\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/iam-examples-server-certificates.md |
612870e14bdd-0 | To enable HTTPS connections to your website or application on AWS, you need an SSL/TLS *server certificate*\. To use a certificate that you obtained from an external provider with your website or application on AWS, you must upload the certificate to IAM or import it into AWS Certificate Manager\.
In this example, a series of Node\.js modules are used to handle server certificates in IAM\. The Node\.js modules use the SDK for JavaScript to manage server certificates using these methods of the `AWS.IAM` client class:
+ [listServerCertificates](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/IAM.html#listServerCertificates-property)
+ [getServerCertificate](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/IAM.html#getServerCertificate-property)
+ [updateServerCertificate](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/IAM.html#updateServerCertificate-property)
+ [deleteServerCertificate](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/IAM.html#deleteServerCertificate-property) | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/iam-examples-server-certificates.md |
612870e14bdd-1 | For more information about server certificates, see [Working with Server Certificates](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_server-certs.html) in the *IAM User Guide*\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/iam-examples-server-certificates.md |
c3d5937e4b2e-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/iam-examples-server-certificates.md |
8e65ceeea112-0 | Create a Node\.js module with the file name `iam_listservercerts.js`\. Be sure to configure the SDK as previously shown\. To access IAM, create an `AWS.IAM` service object\. Call the `listServerCertificates` method of the `AWS.IAM` service object\.
```
// Load the AWS SDK for Node.js
var AWS = require('aws-sdk');
// Set the region
AWS.config.update({region: 'REGION'});
// Create the IAM service object
var iam = new AWS.IAM({apiVersion: '2010-05-08'});
iam.listServerCertificates({}, function(err, data) {
if (err) {
console.log("Error", err);
} else {
console.log("Success", data);
}
});
```
To run the example, type the following at the command line\.
```
node iam_listservercerts.js
``` | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/iam-examples-server-certificates.md |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.