id
stringlengths 14
16
| text
stringlengths 1
2.43k
| source
stringlengths 99
229
|
---|---|---|
b14a9b8a8b98-0 | To create this application you'll need resources from multiple services that must be connected and configured in both the code of the browser script and the Node\.js code of the Lambda function\.
**To construct the tutorial application and the Lambda function it uses**
1. Create a working directory on your computer for this tutorial\.
On Linux or Mac let's use `~/MyLambdaApp`; on Windows let's use `C:\MyLambdaApp`\. From now on we'll just call it `MyLambdaApp`\.
1. Download `slotassets.zip` from the [code example archive on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/lambda/tutorial/slotassets.zip)\. This archive contains the browser assets that are used by the application, the Node\.js code that's used in the Lambda function, and several setup scripts\. In this tutorial, you modify the `index.html` file and upload all the browser asset files to an Amazon S3 bucket you provision for this application\. As part of creating the Lambda function, you also modify the Node\.js code in `slotpull.js` before uploading it to the Amazon S3 bucket\.
Unzip the contents of `slotassets.zip` as the directory `slotassets` in `MyLambdaApp`\. The `slotassets` directory should contain the 30 files\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/using-lambda-functions.md |
b14a9b8a8b98-1 | 1. [Create an Amazon S3 bucket configured as a static website](using-lambda-s3-setup.md)\.
1. [Prepare the browser script](using-lambda-browser-script.md)\. Save the edited copy of `index.html` for upload to Amazon S3\.
1. [Create a Lambda execution role in IAM](using-lambda-iam-role-setup.md)\.
1. [Create and populate an Amazon DynamoDB table](using-lambda-ddb-setup.md)\.
1. [Prepare and create the Lambda function](using-lambda-function-prep.md)\.
1. [Run the Lambda function\.](running-lambda-function.md) | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/using-lambda-functions.md |
ede99fcfab97-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 list all subscriptions to an Amazon SNS topic\.
+ How to subscribe an email address, an application endpoint, or an AWS Lambda function to an Amazon SNS topic\.
+ How to unsubscribe from Amazon SNS topics\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/sns-examples-subscribing-unubscribing-topics.md |
1845b4465dde-0 | In this example, you use a series of Node\.js modules to publish notification messages to Amazon SNS topics\. 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#subscribe-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SNS.html#subscribe-property)
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SNS.html#confirmSubscription-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SNS.html#confirmSubscription-property)
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SNS.html#listSubscriptionsByTopic-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SNS.html#listSubscriptionsByTopic-property) | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/sns-examples-subscribing-unubscribing-topics.md |
1845b4465dde-1 | + [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SNS.html#unsubscribe-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SNS.html#unsubscribe-property) | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/sns-examples-subscribing-unubscribing-topics.md |
857635294f34-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-subscribing-unubscribing-topics.md |
6f56a6781728-0 | In this example, use a Node\.js module to list all subscriptions to an Amazon SNS topic\. Create a Node\.js module with the file name `sns_listsubscriptions.js`\. Configure the SDK as previously shown\.
Create an object containing the `TopicArn` parameter for the topic whose subscriptions you want to list\. Pass the parameters to the `listSubscriptionsByTopic` method of the `AWS.SNS` client class\. To call the `listSubscriptionsByTopic` 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'});
const params = {
TopicArn : 'TOPIC_ARN'
}
// Create promise and SNS service object
var subslistPromise = new AWS.SNS({apiVersion: '2010-03-31'}).listSubscriptionsByTopic(params).promise();
// Handle promise's fulfilled/rejected states
subslistPromise.then(
function(data) {
console.log(data);
}).catch(
function(err) { | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/sns-examples-subscribing-unubscribing-topics.md |
6f56a6781728-1 | 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_listsubscriptions.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_listsubscriptions.js)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/sns-examples-subscribing-unubscribing-topics.md |
af90a730253a-0 | In this example, use a Node\.js module to subscribe an email address so that it receives SMTP email messages from an Amazon SNS topic\. Create a Node\.js module with the file name `sns_subscribeemail.js`\. Configure the SDK as previously shown\.
Create an object containing the `Protocol` parameter to specify the `email` protocol, the `TopicArn` for the topic to subscribe to, and an email address as the message `Endpoint`\. Pass the parameters to the `subscribe` method of the `AWS.SNS` client class\. You can use the `subscribe` method to subscribe several different endpoints to an Amazon SNS topic, depending on the values used for parameters passed, as other examples in this topic will show\.
To call the `subscribe` 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 subscribe/email parameters
var params = {
Protocol: 'EMAIL', /* required */
TopicArn: 'TOPIC_ARN', /* required */
Endpoint: 'EMAIL_ADDRESS'
};
// Create promise and SNS service object | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/sns-examples-subscribing-unubscribing-topics.md |
af90a730253a-1 | Endpoint: 'EMAIL_ADDRESS'
};
// Create promise and SNS service object
var subscribePromise = new AWS.SNS({apiVersion: '2010-03-31'}).subscribe(params).promise();
// Handle promise's fulfilled/rejected states
subscribePromise.then(
function(data) {
console.log("Subscription ARN is " + data.SubscriptionArn);
}).catch(
function(err) {
console.error(err, err.stack);
});
```
To run the example, type the following at the command line\.
```
node sns_subscribeemail.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_subscribeemail.js)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/sns-examples-subscribing-unubscribing-topics.md |
8a3f04bc92ee-0 | In this example, use a Node\.js module to subscribe a mobile application endpoint so it receives notifications from an Amazon SNS topic\. Create a Node\.js module with the file name `sns_subscribeapp.js`\. Configure the SDK as previously shown\.
Create an object containing the `Protocol` parameter to specify the `application` protocol, the `TopicArn` for the topic to subscribe to, and the ARN of a mobile application endpoint for the `Endpoint` parameter\. Pass the parameters to the `subscribe` method of the `AWS.SNS` client class\.
To call the `subscribe` 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 subscribe/email parameters
var params = {
Protocol: 'application', /* required */
TopicArn: 'TOPIC_ARN', /* required */
Endpoint: 'MOBILE_ENDPOINT_ARN'
};
// Create promise and SNS service object
var subscribePromise = new AWS.SNS({apiVersion: '2010-03-31'}).subscribe(params).promise(); | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/sns-examples-subscribing-unubscribing-topics.md |
8a3f04bc92ee-1 | var subscribePromise = new AWS.SNS({apiVersion: '2010-03-31'}).subscribe(params).promise();
// Handle promise's fulfilled/rejected states
subscribePromise.then(
function(data) {
console.log("Subscription ARN is " + data.SubscriptionArn);
}).catch(
function(err) {
console.error(err, err.stack);
});
```
To run the example, type the following at the command line\.
```
node sns_subscribeapp.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_subscribeapp.js)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/sns-examples-subscribing-unubscribing-topics.md |
f354d22dc5c6-0 | In this example, use a Node\.js module to subscribe an AWS Lambda function so it receives notifications from an Amazon SNS topic\. Create a Node\.js module with the file name `sns_subscribelambda.js`\. Configure the SDK as previously shown\.
Create an object containing the `Protocol` parameter, specifying the `lambda` protocol, the `TopicArn` for the topic to subscribe to, and the ARN of an AWS Lambda function as the `Endpoint` parameter\. Pass the parameters to the `subscribe` method of the `AWS.SNS` client class\.
To call the `subscribe` 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 subscribe/email parameters
var params = {
Protocol: 'lambda', /* required */
TopicArn: 'TOPIC_ARN', /* required */
Endpoint: 'LAMBDA_FUNCTION_ARN'
};
// Create promise and SNS service object | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/sns-examples-subscribing-unubscribing-topics.md |
f354d22dc5c6-1 | Endpoint: 'LAMBDA_FUNCTION_ARN'
};
// Create promise and SNS service object
var subscribePromise = new AWS.SNS({apiVersion: '2010-03-31'}).subscribe(params).promise();
// Handle promise's fulfilled/rejected states
subscribePromise.then(
function(data) {
console.log("Subscription ARN is " + data.SubscriptionArn);
}).catch(
function(err) {
console.error(err, err.stack);
});
```
To run the example, type the following at the command line\.
```
node sns_subscribelambda.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_subscribelambda.js)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/sns-examples-subscribing-unubscribing-topics.md |
2b3fa4e6c67f-0 | In this example, use a Node\.js module to unsubscribe an Amazon SNS topic subscription\. Create a Node\.js module with the file name `sns_unsubscribe.js`\. Configure the SDK as previously shown\.
Create an object containing the `SubscriptionArn` parameter, specifying the ARN of the subscription to unsubscribe\. Pass the parameters to the `unsubscribe` method of the `AWS.SNS` client class\.
To call the `unsubscribe` 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 subscribePromise = new AWS.SNS({apiVersion: '2010-03-31'}).unsubscribe({SubscriptionArn : TOPIC_SUBSCRIPTION_ARN}).promise();
// Handle promise's fulfilled/rejected states
subscribePromise.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-subscribing-unubscribing-topics.md |
2b3fa4e6c67f-1 | }).catch(
function(err) {
console.error(err, err.stack);
});
```
To run the example, type the following at the command line\.
```
node sns_unsubscribe.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_unsubscribe.js)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/sns-examples-subscribing-unubscribing-topics.md |
d48076416fd1-0 | Rather than using promises, you should consider using async/await\. Async functions are simpler and take less boilerplate than using promises\. Await can only be used in an async function to asynchronously wait for a value\.
The following example uses async/await to list all of your Amazon DynamoDB tables in `us-west-2`\.
```
(async function () {
const DDB = require('@aws-sdk/client-dynamodb')
const dbClient = new DDB.DynamoDBClient({ region: 'us-west-2' })
const command = new DDB.ListTablesCommand({})
try {
const results = await dbClient.send(command)
console.log(results.TableNames.join('\n'))
} catch (err) {
console.error(err)
}
})()
```
**Note**
Not all browsers support async/await\. See [Async functions](https://caniuse.com/#feat=async-functions) for a list of browsers with async/await support\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/using-async-await.md |
5f9e1d2dea50-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 read and write batches of items in a DynamoDB table\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/dynamodb-example-table-read-write-batch.md |
13570c66d027-0 | In this example, you use a series of Node\.js modules to put a batch of items in a DynamoDB table as well as read a batch of items\. The code uses the SDK for JavaScript to perform batch read and write operations using these methods of the DynamoDB client class:
+ [batchGetItem](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB.html#batchGetItem-property)
+ [batchWriteItem](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB.html#batchWriteItem-property) | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/dynamodb-example-table-read-write-batch.md |
2b606a2661dd-0 | To set up and run this example, first complete these tasks:
+ Install Node\.js\. For more information, see the [Node\.js website](https://nodejs.org)\.
+ Create a shared configurations file with your user credentials\. For more information about providing a shared credentials file, see [Loading Credentials in Node\.js from the Shared Credentials File](loading-node-credentials-shared.md)\.
+ Create a DynamoDB table whose items you can access\. For more information about creating a DynamoDB table, see [Creating and Using Tables in DynamoDB](dynamodb-examples-using-tables.md)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/dynamodb-example-table-read-write-batch.md |
eff755895d51-0 | Create a Node\.js module with the file name `ddb_batchgetitem.js`\. Be sure to configure the SDK as previously shown\. To access DynamoDB, create an `AWS.DynamoDB` service object\. Create a JSON object containing the parameters needed to get a batch of items, which in this example includes the name of one or more tables from which to read, the values of keys to read in each table, and the projection expression that specifies the attributes to return\. Call the `batchGetItem` method of the DynamoDB service object\.
```
// Load the AWS SDK for Node.js
var AWS = require('aws-sdk');
// Set the region
AWS.config.update({region: 'REGION'});
// Create DynamoDB service object
var ddb = new AWS.DynamoDB({apiVersion: '2012-08-10'});
var params = {
RequestItems: {
'TABLE_NAME': {
Keys: [
{'KEY_NAME': {N: 'KEY_VALUE_1'}},
{'KEY_NAME': {N: 'KEY_VALUE_2'}},
{'KEY_NAME': {N: 'KEY_VALUE_3'}}
],
ProjectionExpression: 'KEY_NAME, ATTRIBUTE'
}
}
}; | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/dynamodb-example-table-read-write-batch.md |
eff755895d51-1 | ],
ProjectionExpression: 'KEY_NAME, ATTRIBUTE'
}
}
};
ddb.batchGetItem(params, function(err, data) {
if (err) {
console.log("Error", err);
} else {
data.Responses.TABLE_NAME.forEach(function(element, index, array) {
console.log(element);
});
}
});
```
To run the example, type the following at the command line\.
```
node ddb_batchgetitem.js
```
This example code can be found [here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/dynamodb/ddb_batchgetitem.js)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/dynamodb-example-table-read-write-batch.md |
994fc299ec31-0 | Create a Node\.js module with the file name `ddb_batchwriteitem.js`\. Be sure to configure the SDK as previously shown\. To access DynamoDB, create an `AWS.DynamoDB` service object\. Create a JSON object containing the parameters needed to get a batch of items, which in this example includes the table into which you want to write items, the key\(s\) you want to write for each item, and the attributes along with their values\. Call the `batchWriteItem` method of the DynamoDB service object\.
```
// Load the AWS SDK for Node.js
var AWS = require('aws-sdk');
// Set the region
AWS.config.update({region: 'REGION'});
// Create DynamoDB service object
var ddb = new AWS.DynamoDB({apiVersion: '2012-08-10'});
var params = {
RequestItems: {
"TABLE_NAME": [
{
PutRequest: {
Item: {
"KEY": { "N": "KEY_VALUE" },
"ATTRIBUTE_1": { "S": "ATTRIBUTE_1_VALUE" },
"ATTRIBUTE_2": { "N": "ATTRIBUTE_2_VALUE" }
}
}
},
{
PutRequest: { | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/dynamodb-example-table-read-write-batch.md |
994fc299ec31-1 | }
}
},
{
PutRequest: {
Item: {
"KEY": { "N": "KEY_VALUE" },
"ATTRIBUTE_1": { "S": "ATTRIBUTE_1_VALUE" },
"ATTRIBUTE_2": { "N": "ATTRIBUTE_2_VALUE" }
}
}
}
]
}
};
ddb.batchWriteItem(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 ddb_batchwriteitem.js
```
This example code can be found [here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/dynamodb/ddb_batchwriteitem.js)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/dynamodb-example-table-read-write-batch.md |
4230428c7115-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 publish messages to an Amazon SNS topic\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/sns-examples-publishing-messages.md |
33a62035e421-0 | In this example, you use a series of Node\.js modules to publish messages from Amazon SNS to topic endpoints, emails, or phone numbers\. The Node\.js modules use the SDK for JavaScript to send messages using this method of the `AWS.SNS` client class:
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SNS.html#publish-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SNS.html#publish-property) | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/sns-examples-publishing-messages.md |
ce26713c1485-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-publishing-messages.md |
1ad82e245fb7-0 | In this example, use a Node\.js module to publish a message to an Amazon SNS topic\. Create a Node\.js module with the file name `sns_publishtotopic.js`\. Configure the SDK as previously shown\.
Create an object containing the parameters for publishing a message, including the message text and the ARN of the SNS topic\. For details on available SMS attributes, see [SetSMSAttributes](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SNS.html#setSMSAttributes-property)\.
Pass the parameters to the `publish` method of the `AWS.SNS` client class\. Create a promise for invoking an Amazon SNS service object, passing the parameters object\. Then handle the response in the promise callback\.
```
// Load the AWS SDK for Node.js
var AWS = require('aws-sdk');
// Set region
AWS.config.update({region: 'REGION'});
// Create publish parameters
var params = {
Message: 'MESSAGE_TEXT', /* required */
TopicArn: 'TOPIC_ARN'
};
// Create promise and SNS service object
var publishTextPromise = new AWS.SNS({apiVersion: '2010-03-31'}).publish(params).promise(); | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/sns-examples-publishing-messages.md |
1ad82e245fb7-1 | var publishTextPromise = new AWS.SNS({apiVersion: '2010-03-31'}).publish(params).promise();
// Handle promise's fulfilled/rejected states
publishTextPromise.then(
function(data) {
console.log(`Message ${params.Message} send sent to the topic ${params.TopicArn}`);
console.log("MessageID is " + data.MessageId);
}).catch(
function(err) {
console.error(err, err.stack);
});
```
To run the example, type the following at the command line\.
```
node sns_publishtotopic.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_publishtotopic.js)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/sns-examples-publishing-messages.md |
2f64fac813a1-0 | Not all services are immediately available in the SDK or in all regions\.
To install a service from the AWS SDK for JavaScript using [npm, the Node\.js package manager](https://www.npmjs.com/), enter the following command, where *SERVICE* is the name of a service, such as `s3`\.
```
npm install @aws-sdk/client-SERVICE
``` | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/installing-jssdk.md |
bf30e249d1fe-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 the `package.json` manifest for your project\.
+ How to install and include the modules that your project uses\.
+ How to create an Amazon Simple Storage Service \(Amazon S3\) service object from the `AWS.S3` client class\.
+ How to create an Amazon S3 bucket and upload an object to that bucket\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/getting-started-nodejs.md |
958da718fa65-0 | The example shows how to set up and run a simple Node\.js module that creates an Amazon S3 bucket, then adds a text object to it\.
Because bucket names in Amazon S3 must be globally unique, this example includes a third\-party Node\.js module that generates a unique ID value that you can incorporate into the bucket name\. This additional module is named `uuid`\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/getting-started-nodejs.md |
32ec6e2389d5-0 | To set up and run this example, you must first complete these tasks:
+ Create a working directory for developing your Node\.js module\. For this example we'll use `awsnodesample`\. Note that the directory must be created in a location that can be updated by applications\. For example, in Windows, do not create the directory under `C:\Program Files`\.
+ Install Node\.js\. For more information, see the [Node\.js website](https://nodejs.org)\. You can find downloads of the current and LTS versions of Node\.js for a variety of operating systems at [https://nodejs\.org/en/download/current/](https://nodejs.org/en/download/current/)\.
**Contents**
+ [The Scenario](#getting-started-nodejs-scenario)
+ [Prerequisite Tasks](#getting-started-nodejs-prerequisites)
+ [Step 1: Configure Your Credentials](#getting-started-nodejs-credentials)
+ [Step 2: Create the Package JSON for the Project](#getting-started-nodejs-download)
+ [Step 3: Install the Amazon S3 Package and Dependencies](#getting-started-nodejs-install-sdk)
+ [Step 4: Write the Node\.js Code](#getting-started-nodejs-js-code)
+ [Step 5: Run the Example](#getting-started-nodejs-run-sample) | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/getting-started-nodejs.md |
270b1619fb02-0 | You need to provide credentials to AWS so that only your account and its resources are accessed by the SDK\. For more information about obtaining your account credentials, see [Getting Your Credentials](getting-your-credentials.md)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/getting-started-nodejs.md |
47e2738404f5-0 | After you create the `awsnodesample` project directory, you create and add a `package.json` file for holding the metadata for your Node\.js project\. For details about using `package.json` in a Node\.js project, see [What is the file package\.json?](https://nodejs.org/en/knowledge/getting-started/npm/what-is-the-file-package-json/)
In the project directory, create a new file named `package.json`\. Then add this JSON to the file\.
```
{
"dependencies": {},
"name": "aws-nodejs-sample",
"description": "A simple Node.js application illustrating usage of the AWS SDK for Node.js.",
"version": "1.0.1",
"main": "sample.js",
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "NAME",
"license": "ISC"
}
``` | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/getting-started-nodejs.md |
47e2738404f5-1 | },
"author": "NAME",
"license": "ISC"
}
```
Save the file\. As you install the modules you need, the `dependencies` portion of the file will be completed\. You can find a JSON file that shows an example of these dependencies [here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_codenodegetstarted/example_package.json)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/getting-started-nodejs.md |
6bd56582365f-0 | Install the Amazon S3 package using [npm \(the Node\.js package manager\)](https://www.npmjs.com)\.
From the `awsnodesample` directory in the package, enter the following command to install the Amazon S3 package\.
```
npm install @aws-sdk/client-s3
```
This command installs the Amazon S3 package in your project, and updates `package.json` to list Amazon S3 as a project dependency\. You can find information about this package by searching for "aws\-sdk" on the [npm website](https://www.npmjs.com)\.
Next, install the `uuid` module to the project by typing the following at the command line, which installs the module and updates `package.json`\. For more information about `uuid`, see the module's page at [https://www\.npmjs\.com/package/uuid](https://www.npmjs.com/package/uuid)\.
```
npm install uuid
```
If you see the following error message:
```
npm WARN deprecated node-uuid@1.4.8: Use uuid module instead
```
Type these commands at the command line:
```
npm uninstall --save node-uuid
npm install --save uuid | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/getting-started-nodejs.md |
6bd56582365f-1 | ```
npm uninstall --save node-uuid
npm install --save uuid
```
These packages and their associated code are installed in the `node_modules` subdirectory of your project\.
For more information about installing Node\.js packages, see [Downloading and installing packages locally](https://docs.npmjs.com/getting-started/installing-npm-packages-locally) and [Creating Node\.js Modules](https://docs.npmjs.com/getting-started/creating-node-modules) on the [npm \(Node\.js package manager\) website](https://www.npmjs.com)\. For information about downloading and installing the AWS SDK for JavaScript, see [Installing the SDK for JavaScript](installing-jssdk.md)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/getting-started-nodejs.md |
0f282a4cb417-0 | Create a new file named `sample.js` to contain the example code\. Begin by adding the `require` function calls to include the Amazon S3 and `uuid` packages\.
Create a unique bucket name for the new Amazon S3 bucket by appending a unique ID value to a recognizable prefix, in this case `'node-sdk-sample-'`\. Generate the unique ID by calling the `uuid` module\. Then create a name for the `Key` parameter used to upload an object to the bucket\.
Create `CreateBucketCommand` and `PutObjectCommand` objects to encapsulate the properties of the associated `S3Client` service object requests\. Call the `send` command with the `CreateBucketCommand` and `PutObjectCommand` objects to create a new Amazon S3 bucket and upload the object to it\.
```
(async function() {
// Load the S3 client and commands for Node.js
const {
S3Client,
CreateBucketCommand,
PutObjectCommand
} = require('@aws-sdk/client-s3')
var uuid = require('uuid')
// Unique bucket name
const bucketName = 'node-sdk-sample-' + uuid.v4()
// Name for uploaded object
const keyName = 'hello_world.txt'
const client = new S3Client({}) | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/getting-started-nodejs.md |
0f282a4cb417-1 | const keyName = 'hello_world.txt'
const client = new S3Client({})
const createCommand = new CreateBucketCommand({
Bucket: bucketName
})
const putCommand = new PutObjectCommand({
Bucket: bucketName,
Key: keyName,
Body: 'Hello World!'
})
try {
await client.send(createCommand)
await client.send(putCommand)
console.log('Successfully uploaded data to ' + bucketName + '/' + keyName)
} catch (err) {
console.error(err, err.stack)
}
})()
```
The example code can be found [here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/nodegetstarted/sampleV3.js)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/getting-started-nodejs.md |
08cc45809862-0 | Enter the following command to run the example\.
```
node sample.js
```
If the upload is successful, you'll see a confirmation message at the command line\. You can also find the bucket and the uploaded text object in the [Amazon S3 console](https://console.aws.amazon.com/s3/)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/getting-started-nodejs.md |
68a0177d68f0-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 basic information about your Amazon EC2 instances\.
+ How to start and stop detailed monitoring of an Amazon EC2 instance\.
+ How to start and stop an Amazon EC2 instance\.
+ How to reboot an Amazon EC2 instance\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/ec2-example-managing-instances.md |
b2e833eeda0f-0 | In this example, you use a series of Node\.js modules to perform several basic instance management operations\. The Node\.js modules use the SDK for JavaScript to manage instances by using these Amazon EC2 client class methods:
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/EC2.html#describeInstances-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/EC2.html#describeInstances-property)
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/EC2.html#monitorInstances-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/EC2.html#monitorInstances-property)
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/EC2.html#unmonitorInstances-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/EC2.html#unmonitorInstances-property)
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/EC2.html#startInstances-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/EC2.html#startInstances-property) | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/ec2-example-managing-instances.md |
b2e833eeda0f-1 | + [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/EC2.html#stopInstances-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/EC2.html#stopInstances-property)
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/EC2.html#rebootInstances-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/EC2.html#rebootInstances-property)
For more information about the lifecycle of Amazon EC2 instances, see [Instance Lifecycle](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-lifecycle.html) in the *Amazon EC2 User Guide for Linux Instances*\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/ec2-example-managing-instances.md |
9b1783e7eed1-0 | To set up and run this example, 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)\.
+ Create an Amazon EC2 instance\. For more information about creating Amazon EC2 instances, see [Amazon EC2 Instances](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Instances.html) in the *Amazon EC2 User Guide for Linux Instances* or [Amazon EC2 Instances](https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/Instances.html) in the *Amazon EC2 User Guide for Windows Instances*\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/ec2-example-managing-instances.md |
a80cd62335b6-0 | Create a Node\.js module with the file name `ec2_describeinstances.js`\. Be sure to configure the SDK as previously shown\. To access Amazon EC2, create an `AWS.EC2` service object\. Call the `describeInstances` method of the Amazon EC2 service object to retrieve a detailed description of your instances\.
```
// Load the AWS SDK for Node.js
var AWS = require('aws-sdk');
// Set the region
AWS.config.update({region: 'REGION'});
// Create EC2 service object
var ec2 = new AWS.EC2({apiVersion: '2016-11-15'});
var params = {
DryRun: false
};
// Call EC2 to retrieve policy for selected bucket
ec2.describeInstances(params, function(err, data) {
if (err) {
console.log("Error", err.stack);
} else {
console.log("Success", JSON.stringify(data));
}
});
```
To run the example, type the following at the command line\.
```
node ec2_describeinstances.js
``` | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/ec2-example-managing-instances.md |
a80cd62335b6-1 | ```
node ec2_describeinstances.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_describeinstances.js)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/ec2-example-managing-instances.md |
b9a665df6fc5-0 | Create a Node\.js module with the file name `ec2_monitorinstances.js`\. Be sure to configure the SDK as previously shown\. To access Amazon EC2, create an `AWS.EC2` service object\. Add the instance IDs of the instances for which you want to control monitoring\.
Based on the value of a command\-line argument \(`ON` or `OFF`\), call either the `monitorInstances` method of the Amazon EC2 service object to begin detailed monitoring of the specified instances or call the `unmonitorInstances` method\. Use the `DryRun` parameter to test whether you have permission to change instance monitoring before you attempt to change the monitoring of these instances\.
```
// Load the AWS SDK for Node.js
var AWS = require('aws-sdk');
// Set the region
AWS.config.update({region: 'REGION'});
// Create EC2 service object
var ec2 = new AWS.EC2({apiVersion: '2016-11-15'});
var params = {
InstanceIds: ['INSTANCE_ID'],
DryRun: true
};
if (process.argv[2].toUpperCase() === "ON") {
// Call EC2 to start monitoring the selected instances
ec2.monitorInstances(params, function(err, data) { | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/ec2-example-managing-instances.md |
b9a665df6fc5-1 | // Call EC2 to start monitoring the selected instances
ec2.monitorInstances(params, function(err, data) {
if (err && err.code === 'DryRunOperation') {
params.DryRun = false;
ec2.monitorInstances(params, function(err, data) {
if (err) {
console.log("Error", err);
} else if (data) {
console.log("Success", data.InstanceMonitorings);
}
});
} else {
console.log("You don't have permission to change instance monitoring.");
}
});
} else if (process.argv[2].toUpperCase() === "OFF") {
// Call EC2 to stop monitoring the selected instances
ec2.unmonitorInstances(params, function(err, data) {
if (err && err.code === 'DryRunOperation') {
params.DryRun = false;
ec2.unmonitorInstances(params, function(err, data) {
if (err) {
console.log("Error", err);
} else if (data) {
console.log("Success", data.InstanceMonitorings); | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/ec2-example-managing-instances.md |
b9a665df6fc5-2 | } else if (data) {
console.log("Success", data.InstanceMonitorings);
}
});
} else {
console.log("You don't have permission to change instance monitoring.");
}
});
}
```
To run the example, type the following at the command line, specifying `ON` to begin detailed monitoring or `OFF` to discontinue monitoring\.
```
node ec2_monitorinstances.js ON
```
This example code can be found [here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/ec2/ec2_monitorinstances.js)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/ec2-example-managing-instances.md |
4a29c0842cb8-0 | Create a Node\.js module with the file name `ec2_startstopinstances.js`\. Be sure to configure the SDK as previously shown\. To access Amazon EC2, create an `AWS.EC2` service object\. Add the instance IDs of the instances you want to start or stop\.
Based on the value of a command\-line argument \(`START` or `STOP`\), call either the `startInstances` method of the Amazon EC2 service object to start the specified instances, or the `stopInstances` method to stop them\. Use the `DryRun` parameter to test whether you have permission before actually attempting to start or stop the selected instances\.
```
// Load the AWS SDK for Node.js
var AWS = require('aws-sdk');
// Set the region
AWS.config.update({region: 'REGION'});
// Create EC2 service object
var ec2 = new AWS.EC2({apiVersion: '2016-11-15'});
var params = {
InstanceIds: [process.argv[3]],
DryRun: true
};
if (process.argv[2].toUpperCase() === "START") {
// Call EC2 to start the selected instances
ec2.startInstances(params, function(err, data) { | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/ec2-example-managing-instances.md |
4a29c0842cb8-1 | // Call EC2 to start the selected instances
ec2.startInstances(params, function(err, data) {
if (err && err.code === 'DryRunOperation') {
params.DryRun = false;
ec2.startInstances(params, function(err, data) {
if (err) {
console.log("Error", err);
} else if (data) {
console.log("Success", data.StartingInstances);
}
});
} else {
console.log("You don't have permission to start instances.");
}
});
} else if (process.argv[2].toUpperCase() === "STOP") {
// Call EC2 to stop the selected instances
ec2.stopInstances(params, function(err, data) {
if (err && err.code === 'DryRunOperation') {
params.DryRun = false;
ec2.stopInstances(params, function(err, data) {
if (err) {
console.log("Error", err);
} else if (data) {
console.log("Success", data.StoppingInstances);
} | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/ec2-example-managing-instances.md |
4a29c0842cb8-2 | } else if (data) {
console.log("Success", data.StoppingInstances);
}
});
} else {
console.log("You don't have permission to stop instances");
}
});
}
```
To run the example, type the following at the command line specifying `START` to start the instances or `STOP` to stop them\.
```
node ec2_startstopinstances.js START INSTANCE_ID
```
This example code can be found [here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/ec2/ec2_startstopinstances.js)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/ec2-example-managing-instances.md |
c0321e9a0df6-0 | Create a Node\.js module with the file name `ec2_rebootinstances.js`\. Be sure to configure the SDK as previously shown\. To access Amazon EC2, create an Amazon EC2 service object\. Add the instance IDs of the instances you want to reboot\. Call the `rebootInstances` method of the `AWS.EC2` service object to reboot the specified instances\. Use the `DryRun` parameter to test whether you have permission to reboot these instances before actually attempting to reboot them\.
```
// Load the AWS SDK for Node.js
var AWS = require('aws-sdk');
// Set the region
AWS.config.update({region: 'REGION'});
// Create EC2 service object
var ec2 = new AWS.EC2({apiVersion: '2016-11-15'});
var params = {
InstanceIds: ['INSTANCE_ID'],
DryRun: true
};
// Call EC2 to reboot instances
ec2.rebootInstances(params, function(err, data) {
if (err && err.code === 'DryRunOperation') {
params.DryRun = false;
ec2.rebootInstances(params, function(err, data) {
if (err) { | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/ec2-example-managing-instances.md |
c0321e9a0df6-1 | ec2.rebootInstances(params, function(err, data) {
if (err) {
console.log("Error", err);
} else if (data) {
console.log("Success", data);
}
});
} else {
console.log("You don't have permission to reboot instances.");
}
});
```
To run the example, type the following at the command line\.
```
node ec2_rebootinstances.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_rebootinstances.js)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/ec2-example-managing-instances.md |
d9850d1e94b6-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 information about your security groups\.
+ How to create a security group to access an Amazon EC2 instance\.
+ How to delete an existing security group\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/ec2-example-security-groups.md |
8328a9cdf001-0 | An Amazon EC2 security group acts as a virtual firewall that controls the traffic for one or more instances\. You add rules to each security group to allow traffic to or from its associated instances\. You can modify the rules for a security group at any time; the new rules are automatically applied to all instances that are associated with the security group\.
In this example, you use a series of Node\.js modules to perform several Amazon EC2 operations involving security groups\. The Node\.js modules use the SDK for JavaScript to manage instances by using the following methods of the Amazon EC2 client class:
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/EC2.html#describeSecurityGroups-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/EC2.html#describeSecurityGroups-property)
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/EC2.html#authorizeSecurityGroupIngress-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/EC2.html#authorizeSecurityGroupIngress-property)
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/EC2.html#createSecurityGroup-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/EC2.html#createSecurityGroup-property) | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/ec2-example-security-groups.md |
8328a9cdf001-1 | + [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/EC2.html#describeVpcs-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/EC2.html#describeVpcs-property)
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/EC2.html#deleteSecurityGroup-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/EC2.html#deleteSecurityGroup-property)
For more information about the Amazon EC2 security groups, see [Amazon EC2 Amazon Security Groups for Linux Instances](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-network-security.html) in the *Amazon EC2 User Guide for Linux Instances* or [Amazon EC2 Security Groups for Windows Instances](https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/using-network-security.html) in the *Amazon EC2 User Guide for Windows Instances*\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/ec2-example-security-groups.md |
39ce74906dc3-0 | To set up and run this example, 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/ec2-example-security-groups.md |
1d2f9a01cd51-0 | Create a Node\.js module with the file name `ec2_describesecuritygroups.js`\. Be sure to configure the SDK as previously shown\. To access Amazon EC2, create an `AWS.EC2` service object\. Create a JSON object to pass as parameters, including the group IDs for the security groups you want to describe\. Then call the `describeSecurityGroups` method of the Amazon EC2 service object\.
```
// Load the AWS SDK for Node.js
var AWS = require('aws-sdk');
// Set the region
AWS.config.update({region: 'REGION'});
// Create EC2 service object
var ec2 = new AWS.EC2({apiVersion: '2016-11-15'});
var params = {
GroupIds: ['SECURITY_GROUP_ID']
};
// Retrieve security group descriptions
ec2.describeSecurityGroups(params, function(err, data) {
if (err) {
console.log("Error", err);
} else {
console.log("Success", JSON.stringify(data.SecurityGroups));
}
});
```
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/ec2-example-security-groups.md |
1d2f9a01cd51-1 | });
```
To run the example, type the following at the command line\.
```
node ec2_describesecuritygroups.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_describesecuritygroups.js)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/ec2-example-security-groups.md |
7012f18d0dcb-0 | Create a Node\.js module with the file name `ec2_createsecuritygroup.js`\. Be sure to configure the SDK as previously shown\. To access Amazon EC2, create an `AWS.EC2` service object\. Create a JSON object for the parameters that specify the name of the security group, a description, and the ID for the VPC\. Pass the parameters to the `createSecurityGroup` method\.
After you successfully create the security group, you can define rules for allowing inbound traffic\. Create a JSON object for parameters that specify the IP protocol and inbound ports on which the Amazon EC2 instance will receive traffic\. Pass the parameters to the `authorizeSecurityGroupIngress` 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'});
// Variable to hold a ID of a VPC
var vpc = null;
// Retrieve the ID of a VPC
ec2.describeVpcs(function(err, data) {
if (err) {
console.log("Cannot retrieve a VPC", err);
} else { | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/ec2-example-security-groups.md |
7012f18d0dcb-1 | if (err) {
console.log("Cannot retrieve a VPC", err);
} else {
vpc = data.Vpcs[0].VpcId;
var paramsSecurityGroup = {
Description: 'DESCRIPTION',
GroupName: 'SECURITY_GROUP_NAME',
VpcId: vpc
};
// Create the instance
ec2.createSecurityGroup(paramsSecurityGroup, function(err, data) {
if (err) {
console.log("Error", err);
} else {
var SecurityGroupId = data.GroupId;
console.log("Success", SecurityGroupId);
var paramsIngress = {
GroupId: 'SECURITY_GROUP_ID',
IpPermissions:[
{
IpProtocol: "tcp",
FromPort: 80,
ToPort: 80,
IpRanges: [{"CidrIp":"0.0.0.0/0"}]
},
{
IpProtocol: "tcp",
FromPort: 22,
ToPort: 22,
IpRanges: [{"CidrIp":"0.0.0.0/0"}]
}
]
}; | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/ec2-example-security-groups.md |
7012f18d0dcb-2 | }
]
};
ec2.authorizeSecurityGroupIngress(paramsIngress, function(err, data) {
if (err) {
console.log("Error", err);
} else {
console.log("Ingress Successfully Set", data);
}
});
}
});
}
});
```
To run the example, type the following at the command line\.
```
node ec2_createsecuritygroup.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_createsecuritygroup.js)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/ec2-example-security-groups.md |
a8473b0caf93-0 | Create a Node\.js module with the file name `ec2_deletesecuritygroup.js`\. Be sure to configure the SDK as previously shown\. To access Amazon EC2, create an `AWS.EC2` service object\. Create the JSON parameters to specify the name of the security group to delete\. Then call the `deleteSecurityGroup` method\.
```
// Load the AWS SDK for Node.js
var AWS = require('aws-sdk');
// Set the region
AWS.config.update({region: 'REGION'});
// Create EC2 service object
var ec2 = new AWS.EC2({apiVersion: '2016-11-15'});
var params = {
GroupId: 'SECURITY_GROUP_ID'
};
// Delete the security group
ec2.deleteSecurityGroup(params, function(err, data) {
if (err) {
console.log("Error", err);
} else {
console.log("Security Group Deleted");
}
});
```
To run the example, type the following at the command line\.
```
node ec2_deletesecuritygroup.js
``` | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/ec2-example-security-groups.md |
a8473b0caf93-1 | ```
node ec2_deletesecuritygroup.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_deletesecuritygroup.js)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/ec2-example-security-groups.md |
b42fc7cdcb57-0 | For the latest AWS terminology, see the [AWS glossary](https://docs.aws.amazon.com/general/latest/gr/glos-chap.html) in the *AWS General Reference*\. | https://github.com/siagholami/aws-documentation/tree/main/documents/amazon-personalize-developer-guide/doc_source/glossary.md |
a34d0a3583e9-0 | Describes the properties for hyperparameter optimization \(HPO\)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/amazon-personalize-developer-guide/doc_source/API_HPOConfig.md |
7e643c8f158f-0 | **algorithmHyperParameterRanges** <a name="personalize-Type-HPOConfig-algorithmHyperParameterRanges"></a>
The hyperparameters and their allowable ranges\.
Type: [HyperParameterRanges](API_HyperParameterRanges.md) object
Required: No
**hpoObjective** <a name="personalize-Type-HPOConfig-hpoObjective"></a>
The metric to optimize during HPO\.
Type: [HPOObjective](API_HPOObjective.md) object
Required: No
**hpoResourceConfig** <a name="personalize-Type-HPOConfig-hpoResourceConfig"></a>
Describes the resource configuration for HPO\.
Type: [HPOResourceConfig](API_HPOResourceConfig.md) object
Required: No | https://github.com/siagholami/aws-documentation/tree/main/documents/amazon-personalize-developer-guide/doc_source/API_HPOConfig.md |
b5d5deb6dadb-0 | For more information about using this API in one of the language\-specific AWS SDKs, see the following:
+ [AWS SDK for C\+\+](https://docs.aws.amazon.com/goto/SdkForCpp/personalize-2018-05-22/HPOConfig)
+ [AWS SDK for Go](https://docs.aws.amazon.com/goto/SdkForGoV1/personalize-2018-05-22/HPOConfig)
+ [AWS SDK for Java](https://docs.aws.amazon.com/goto/SdkForJava/personalize-2018-05-22/HPOConfig)
+ [AWS SDK for Ruby V3](https://docs.aws.amazon.com/goto/SdkForRubyV3/personalize-2018-05-22/HPOConfig) | https://github.com/siagholami/aws-documentation/tree/main/documents/amazon-personalize-developer-guide/doc_source/API_HPOConfig.md |
aac461e0a50c-0 | Creates a recommendation filter\. For more information, see [Using Filters with Amazon Personalize](https://docs.aws.amazon.com/personalize/latest/dg/filters.html)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/amazon-personalize-developer-guide/doc_source/API_CreateFilter.md |
14f0025a9eab-0 | ```
{
"datasetGroupArn": "string",
"filterExpression": "string",
"name": "string"
}
``` | https://github.com/siagholami/aws-documentation/tree/main/documents/amazon-personalize-developer-guide/doc_source/API_CreateFilter.md |
7632d196b6c5-0 | The request accepts the following data in JSON format\.
** [datasetGroupArn](#API_CreateFilter_RequestSyntax) ** <a name="personalize-CreateFilter-request-datasetGroupArn"></a>
The ARN of the dataset group that the filter will belong to\.
Type: String
Length Constraints: Maximum length of 256\.
Pattern: `arn:([a-z\d-]+):personalize:.*:.*:.+`
Required: Yes
** [filterExpression](#API_CreateFilter_RequestSyntax) ** <a name="personalize-CreateFilter-request-filterExpression"></a>
The filter expression that designates the interaction types that the filter will filter out\. A filter expression must follow the following format:
`EXCLUDE itemId WHERE INTERACTIONS.event_type in ("EVENT_TYPE")`
Where "EVENT\_TYPE" is the type of event to filter out\. To filter out all items with any interactions history, set `"*"` as the EVENT\_TYPE\. For more information, see [Using Filters with Amazon Personalize](https://docs.aws.amazon.com/personalize/latest/dg/filters.html)\.
Type: String
Length Constraints: Minimum length of 1\. Maximum length of 2500\.
Required: Yes | https://github.com/siagholami/aws-documentation/tree/main/documents/amazon-personalize-developer-guide/doc_source/API_CreateFilter.md |
7632d196b6c5-1 | Type: String
Length Constraints: Minimum length of 1\. Maximum length of 2500\.
Required: Yes
** [name](#API_CreateFilter_RequestSyntax) ** <a name="personalize-CreateFilter-request-name"></a>
The name of the filter to create\.
Type: String
Length Constraints: Minimum length of 1\. Maximum length of 63\.
Pattern: `^[a-zA-Z0-9][a-zA-Z0-9\-_]*`
Required: Yes | https://github.com/siagholami/aws-documentation/tree/main/documents/amazon-personalize-developer-guide/doc_source/API_CreateFilter.md |
2327069904b9-0 | ```
{
"filterArn": "string"
}
``` | https://github.com/siagholami/aws-documentation/tree/main/documents/amazon-personalize-developer-guide/doc_source/API_CreateFilter.md |
119ab00d02e7-0 | If the action is successful, the service sends back an HTTP 200 response\.
The following data is returned in JSON format by the service\.
** [filterArn](#API_CreateFilter_ResponseSyntax) ** <a name="personalize-CreateFilter-response-filterArn"></a>
The ARN of the new filter\.
Type: String
Length Constraints: Maximum length of 256\.
Pattern: `arn:([a-z\d-]+):personalize:.*:.*:.+` | https://github.com/siagholami/aws-documentation/tree/main/documents/amazon-personalize-developer-guide/doc_source/API_CreateFilter.md |
ba53a53430bb-0 | **InvalidInputException**
Provide a valid value for the field or parameter\.
HTTP Status Code: 400
**LimitExceededException**
The limit on the number of requests per second has been exceeded\.
HTTP Status Code: 400
**ResourceAlreadyExistsException**
The specified resource already exists\.
HTTP Status Code: 400
**ResourceNotFoundException**
Could not find the specified resource\.
HTTP Status Code: 400 | https://github.com/siagholami/aws-documentation/tree/main/documents/amazon-personalize-developer-guide/doc_source/API_CreateFilter.md |
e7963675e7d8-0 | For more information about using this API in one of the language\-specific AWS SDKs, see the following:
+ [AWS Command Line Interface](https://docs.aws.amazon.com/goto/aws-cli/personalize-2018-05-22/CreateFilter)
+ [AWS SDK for \.NET](https://docs.aws.amazon.com/goto/DotNetSDKV3/personalize-2018-05-22/CreateFilter)
+ [AWS SDK for C\+\+](https://docs.aws.amazon.com/goto/SdkForCpp/personalize-2018-05-22/CreateFilter)
+ [AWS SDK for Go](https://docs.aws.amazon.com/goto/SdkForGoV1/personalize-2018-05-22/CreateFilter)
+ [AWS SDK for Java](https://docs.aws.amazon.com/goto/SdkForJava/personalize-2018-05-22/CreateFilter)
+ [AWS SDK for JavaScript](https://docs.aws.amazon.com/goto/AWSJavaScriptSDK/personalize-2018-05-22/CreateFilter)
+ [AWS SDK for PHP V3](https://docs.aws.amazon.com/goto/SdkForPHPV3/personalize-2018-05-22/CreateFilter) | https://github.com/siagholami/aws-documentation/tree/main/documents/amazon-personalize-developer-guide/doc_source/API_CreateFilter.md |
e7963675e7d8-1 | + [AWS SDK for Python](https://docs.aws.amazon.com/goto/boto3/personalize-2018-05-22/CreateFilter)
+ [AWS SDK for Ruby V3](https://docs.aws.amazon.com/goto/SdkForRubyV3/personalize-2018-05-22/CreateFilter) | https://github.com/siagholami/aws-documentation/tree/main/documents/amazon-personalize-developer-guide/doc_source/API_CreateFilter.md |
134358f89000-0 | In this exercise, you use the AWS Command Line Interface \(AWS CLI\) to explore Amazon Personalize\. You create a campaign that returns movie recommendations for a given user ID\.
Before you start this exercise, do the following:
+ Review the Getting Started [Getting Started Prerequisites](gs-prerequisites.md)\.
+ Set up the AWS CLI, as specified in [Setting Up the AWS CLI](aws-personalize-set-up-aws-cli.md)\.
After you finish this exercise, see [Clean Up Resources](gs-cleanup.md)\.
**Note**
The CLI commands in this exercise were tested on Linux\. For information about using the CLI commands on Windows, see [Specifying Parameter Values for the AWS Command Line Interface](https://docs.aws.amazon.com/cli/latest/userguide/cli-using-param.html) in the *AWS Command Line Interface User Guide*\. | https://github.com/siagholami/aws-documentation/tree/main/documents/amazon-personalize-developer-guide/doc_source/getting-started-cli.md |
3b155ea15033-0 | Follow the steps to create a dataset group, add a dataset to the group, and then populate the dataset using the movie ratings data\.
1. Create a dataset group by running the following command\. You can encrypt the dataset group by passing a [AWS Key Management Service](https://docs.aws.amazon.com/kms/latest/developerguide/overview.html) key ARN and the ARN of an IAM role that has access permissions to that key as input parameters\. For more information about the API, see [CreateDatasetGroup](API_CreateDatasetGroup.md)\.
```
aws personalize create-dataset-group --name MovieRatingDatasetGroup --kms-key-arn arn:aws:kms:us-west-2:01234567890:key/1682a1e7-a94d-4d92-bbdf-837d3b62315e --role-arn arn:aws:iam::01234567890:KMS-key-access
```
The dataset group ARN is displayed, for example:
```
{
"datasetGroupArn": "arn:aws:personalize:us-west-2:acct-id:dataset-group/MovieRatingDatasetGroup"
}
```
Use the `describe-dataset-group` command to display the dataset group you created, specifying the returned dataset group ARN\. | https://github.com/siagholami/aws-documentation/tree/main/documents/amazon-personalize-developer-guide/doc_source/getting-started-cli.md |
3b155ea15033-1 | ```
Use the `describe-dataset-group` command to display the dataset group you created, specifying the returned dataset group ARN\.
```
aws personalize describe-dataset-group \
--dataset-group-arn arn:aws:personalize:us-west-2:acct-id:dataset-group/MovieRatingDatasetGroup
```
The dataset group and its properties are displayed, for example:
```
{
"datasetGroup": {
"name": "MovieRatingDatasetGroup",
"datasetGroupArn": "arn:aws:personalize:us-west-2:acct-id:dataset-group/MovieRatingDatasetGroup",
"status": "ACTIVE",
"creationDateTime": 1542392161.262,
"lastUpdatedDateTime": 1542396513.377
}
}
```
**Note**
Wait until the dataset group's `status` shows as ACTIVE before creating a dataset in the group\. This operation is usually quick\.
If you don't remember the dataset group ARN, use the `list-dataset-groups` command to display all the dataset groups that you created, along with their ARNs\.
```
aws personalize list-dataset-groups | https://github.com/siagholami/aws-documentation/tree/main/documents/amazon-personalize-developer-guide/doc_source/getting-started-cli.md |
3b155ea15033-2 | ```
aws personalize list-dataset-groups
```
**Note**
The `describe-object` and `list-objects` commands are available for most Amazon Personalize objects\. These commands are not shown in the remainder of this exercise but they are available\.
1. Create a schema file in JSON format by saving the following code to a file named `MovieRatingSchema.json`\. The schema matches the headers you previously added to `ratings.csv`\. The schema name is `Interactions`, which matches one of the three types of datasets recognized by Amazon Personalize\. For more information, see [Datasets and Dataset Groups](how-it-works.md#how-it-works-dataset)\.
```
{
"type": "record",
"name": "Interactions",
"namespace": "com.amazonaws.personalize.schema",
"fields": [
{
"name": "USER_ID",
"type": "string"
},
{
"name": "ITEM_ID",
"type": "string"
},
{
"name": "TIMESTAMP",
"type": "long"
}
],
"version": "1.0"
}
``` | https://github.com/siagholami/aws-documentation/tree/main/documents/amazon-personalize-developer-guide/doc_source/getting-started-cli.md |
3b155ea15033-3 | }
],
"version": "1.0"
}
```
1. Create a schema by running the following command\. Specify the file you saved in the previous step\. The example shows the file as belonging to the current folder\. For more information about the API, see [CreateSchema](API_CreateSchema.md)\.
```
aws personalize create-schema \
--name MovieRatingSchema \
--schema file://MovieRatingSchema.json
```
The schema Amazon Resource Name \(ARN\) is displayed, for example:
```
{
"schemaArn": "arn:aws:personalize:us-west-2:acct-id:schema/MovieRatingSchema"
}
```
1. Create an empty dataset by running the following command\. Provide the dataset group ARN and schema ARN that were returned in the previous steps\. The `dataset-type` must match the schema `name` from the previous step\. For more information about the API, see [CreateDataset](API_CreateDataset.md)\.
```
aws personalize create-dataset \
--name MovieRatingDataset \ | https://github.com/siagholami/aws-documentation/tree/main/documents/amazon-personalize-developer-guide/doc_source/getting-started-cli.md |
3b155ea15033-4 | ```
aws personalize create-dataset \
--name MovieRatingDataset \
--dataset-group-arn arn:aws:personalize:us-west-2:acct-id:dataset-group/MovieRatingDatasetGroup \
--dataset-type Interactions \
--schema-arn arn:aws:personalize:us-west-2:acct-id:schema/MovieRatingSchema
```
The dataset ARN is displayed, for example:
```
{
"datasetArn": "arn:aws:personalize:us-west-2:acct-id:dataset/MovieRatingDatasetGroup/INTERACTIONS"
}
```
1. Add the training data to the dataset\.
1. Create a dataset import job by running the following command\. Provide the dataset ARN and Amazon S3 bucket name that were returned in the previous steps\. Supply the AWS Identity and Access Management \(IAM\) role ARN you created in [Creating an IAM Role for Amazon Personalize](aws-personalize-set-up-permissions.md#set-up-create-role-with-permissions)\. For more information about the API, see [CreateDatasetImportJob](API_CreateDatasetImportJob.md)\.
```
aws personalize create-dataset-import-job \ | https://github.com/siagholami/aws-documentation/tree/main/documents/amazon-personalize-developer-guide/doc_source/getting-started-cli.md |
3b155ea15033-5 | ```
aws personalize create-dataset-import-job \
--job-name MovieRatingImportJob \
--dataset-arn arn:aws:personalize:us-west-2:acct-id:dataset/MovieRatingDatasetGroup/INTERACTIONS \
--data-source dataLocation=s3://bucketname/ratings.csv \
--role-arn roleArn
```
The dataset import job ARN is displayed, for example:
```
{
"datasetImportJobArn": "arn:aws:personalize:us-west-2:acct-id:dataset-import-job/MovieRatingImportJob"
}
```
1. Check the status by using the `describe-dataset-import-job` command\. Provide the dataset import job ARN that was returned in the previous step\. For more information about the API, see [DescribeDatasetImportJob](API_DescribeDatasetImportJob.md)\.
```
aws personalize describe-dataset-import-job \
--dataset-import-job-arn arn:aws:personalize:us-west-2:acct-id:dataset-import-job/MovieRatingImportJob
``` | https://github.com/siagholami/aws-documentation/tree/main/documents/amazon-personalize-developer-guide/doc_source/getting-started-cli.md |
3b155ea15033-6 | ```
The properties of the dataset import job, including its status, are displayed\. Initially, the `status` shows as CREATE PENDING, for example:
```
{
"datasetImportJob": {
"jobName": "MovieRatingImportJob",
"datasetImportJobArn": "arn:aws:personalize:us-west-2:acct-id:dataset-import-job/MovieRatingImportJob",
"datasetArn": "arn:aws:personalize:us-west-2:acct-id:dataset/MovieRatingDatasetGroup/INTERACTIONS",
"dataSource": {
"dataLocation": "s3://<bucketname>/ratings.csv"
},
"roleArn": "role-arn",
"status": "CREATE PENDING",
"creationDateTime": 1542392161.837,
"lastUpdatedDateTime": 1542393013.377
}
}
```
The dataset import is complete when the status shows as ACTIVE\. Then you are ready to train the model using the specified dataset\.
**Note**
Importing takes time\. Wait until the dataset import is complete before training the model using the dataset\. | https://github.com/siagholami/aws-documentation/tree/main/documents/amazon-personalize-developer-guide/doc_source/getting-started-cli.md |
766c2fcade19-0 | Two steps are required to initially train a model\. First, you create the configuration for training the model using the [CreateSolution](API_CreateSolution.md) operation\. Second, you train the model using the [CreateSolutionVersion](API_CreateSolutionVersion.md) operation\.
You train a model using a recipe and your training data\. Amazon Personalize provides a set of predefined recipes\. For more information, see [Choosing a Recipe](working-with-predefined-recipes.md)\. For this exercise, you use AutoML, which allows Amazon Personalize to pick the best recipe based on the dataset you created in the preceding step\.
1. Create the configuration for training a model by running the following command\.
```
aws personalize create-solution \
--name MovieSolution \
--dataset-group-arn arn:aws:personalize:us-west-2:acct-id:dataset-group/MovieRatingDatasetGroup \
--perform-auto-ml
```
The solution ARN is displayed, for example:
```
{
"solutionArn": "arn:aws:personalize:us-west-2:acct-id:solution/MovieSolution"
}
``` | https://github.com/siagholami/aws-documentation/tree/main/documents/amazon-personalize-developer-guide/doc_source/getting-started-cli.md |
766c2fcade19-1 | }
```
1. Check the *create* status using the `describe-solution` command\. Provide the solution ARN that was returned in the previous step\. For more information about the API, see [DescribeSolution](API_DescribeSolution.md)\.
```
aws personalize describe-solution \
--solution-arn arn:aws:personalize:us-west-2:acct-id:solution/MovieSolution
```
The properties of the solution and the create `status` are displayed\. Initially, the status shows as CREATE PENDING, for example:
```
{
"solution": {
"name": "MovieSolution",
"solutionArn": "arn:aws:personalize:us-west-2:acct-id:solution/MovieSolution",
"datasetGroupArn": "arn:aws:personalize:us-west-2:acct-id:dataset-group/MovieRatingDatasetGroup",
"performAutoML": true,
"performHPO": false,
"solutionConfig": {
"autoMLConfig": {
"metricName": "precision_at_25",
"recipeList": [
"arn:aws:personalize:::recipe/aws-hrnn"
]
}
}, | https://github.com/siagholami/aws-documentation/tree/main/documents/amazon-personalize-developer-guide/doc_source/getting-started-cli.md |
766c2fcade19-2 | "arn:aws:personalize:::recipe/aws-hrnn"
]
}
},
"creationDateTime": 1543864685.016,
"lastUpdatedDateTime": 1543864685.016,
"status": "CREATE PENDING"
}
}
```
Note the `metricName` and `recipeList`\. Because you specified `performAutoML`, Amazon Personalize chooses the recipe from the list that optimizes that metric\. Because we didn't supply any metadata, the only recipe in the list is the [HRNN](native-recipe-hrnn.md) recipe\.
When the create `status` shows as ACTIVE, the solution configuration is complete and the model is ready for training\.
1. Now that the configuration is ACTIVE, train the model by running the following command\.
```
aws personalize create-solution-version \
--solution-arn arn:aws:personalize:us-west-2:acct-id:solution/MovieSolution
```
The solution version ARN is displayed, for example:
```
{
"solutionVersionArn": "arn:aws:personalize:us-west-2:acct-id:solution/MovieSolution/<version-id>"
}
``` | https://github.com/siagholami/aws-documentation/tree/main/documents/amazon-personalize-developer-guide/doc_source/getting-started-cli.md |
766c2fcade19-3 | }
```
Check the *training* status of the solution version by using the `describe-solution-version` command\. Provide the solution version ARN that was returned in the previous step\. For more information about the API, see [DescribeSolutionVersion](API_DescribeSolutionVersion.md)\.
```
aws personalize describe-solution-version \
--solution-version-arn arn:aws:personalize:us-west-2:acct-id:solution/MovieSolution/version-id
```
The properties of the solution version and the training `status` are displayed\. Initially, the status shows as CREATE PENDING, for example:
```
{
"solutionVersion": {
"solutionVersionArn": "arn:aws:personalize:us-west-2:acct-id:solution/MovieSolution/<version-id>",
...,
"status": "CREATE PENDING"
}
}
```
1. When the latest solution version training `status` shows as ACTIVE, the training is complete\. The `describe-solution-version` response now includes `recipeArn`, which shows the recipe used to train the model as determined by Amazon Personalize, for example:
```
{
"solutionVersion": { | https://github.com/siagholami/aws-documentation/tree/main/documents/amazon-personalize-developer-guide/doc_source/getting-started-cli.md |
766c2fcade19-4 | ```
{
"solutionVersion": {
"solutionVersionArn": "arn:aws:personalize:us-west-2:acct-id:solution/MovieSolution/<version-id>",
"performAutoML": true,
"recipeArn": "arn:aws:personalize:::recipe/aws-hrnn",
"solutionConfig": {
"autoMLConfig": {
"metricName": "precision_at_25",
"recipeList": [
"arn:aws:personalize:::recipe/aws-hrnn"
]
}
},
...
"status": "ACTIVE"
}
}
```
Now you can check the solution version metrics and create a campaign using the solution version\.
**Note**
Training takes time\. Wait until training is complete \(the *training* status of the solution version shows as ACTIVE\) before using this version of the solution in a campaign\. For quicker training, instead of using `perform-auto-ml`, select a specific recipe using the `recipe-arn` parameter\. | https://github.com/siagholami/aws-documentation/tree/main/documents/amazon-personalize-developer-guide/doc_source/getting-started-cli.md |
766c2fcade19-5 | 1. You can validate the performance of the solution version by reviewing its metrics\. Get the metrics for the solution version by running the following command\. Provide the solution version ARN that was returned previously\. For more information about the API, see [GetSolutionMetrics](API_GetSolutionMetrics.md)\.
```
aws personalize get-solution-metrics \
--solution-version-arn arn:aws:personalize:us-west-2:acct-id:solution/MovieSolution/version-id
```
A sample response is shown:
```
{
"solutionVersionArn": "arn:aws:personalize:us-west-2:acct-id:solution/www-solution/<version-id>",
"metrics": {
"arn:aws:personalize:us-west-2:acct-id:model/awspersonalizehrnnmodel-7923fda9": {
"coverage": 0.27,
"mean_reciprocal_rank_at_25": 0.0379,
"normalized_discounted_cumulative_gain_at_5": 0.0405,
"normalized_discounted_cumulative_gain_at_10": 0.0513,
"normalized_discounted_cumulative_gain_at_25": 0.0828,
"precision_at_5": 0.0136, | https://github.com/siagholami/aws-documentation/tree/main/documents/amazon-personalize-developer-guide/doc_source/getting-started-cli.md |
766c2fcade19-6 | "normalized_discounted_cumulative_gain_at_25": 0.0828,
"precision_at_5": 0.0136,
"precision_at_10": 0.0102,
"precision_at_25": 0.0091
}
}
}
``` | https://github.com/siagholami/aws-documentation/tree/main/documents/amazon-personalize-developer-guide/doc_source/getting-started-cli.md |
bb2b30ee66b4-0 | Before you can get recommendations, you must deploy a version of the solution\. Deploying a solution is also known as creating a campaign\. Once you've created your campaign, your client application can get recommendations using the [GetRecommendations](API_RS_GetRecommendations.md) API\.
1. Create a campaign by running the following command\. Provide the solution version ARN that was returned in the previous step\. For more information about the API, see [CreateCampaign](API_CreateCampaign.md)\.
```
aws personalize create-campaign \
--name MovieRecommendationCampaign \
--solution-version-arn arn:aws:personalize:us-west-2:acct-id:solution/MovieSolution/version-id \
--min-provisioned-tps 10
```
A sample response is shown:
```
{
"campaignArn": "arn:aws:personalize:us-west-2:acct-id:campaign/MovieRecommendationCampaign"
}
```
1. Check the deployment status by running the following command\. Provide the campaign ARN that was returned in the previous step\. For more information about the API, see [DescribeCampaign](API_DescribeCampaign.md)\.
```
aws personalize describe-campaign \ | https://github.com/siagholami/aws-documentation/tree/main/documents/amazon-personalize-developer-guide/doc_source/getting-started-cli.md |
bb2b30ee66b4-1 | ```
aws personalize describe-campaign \
--campaign-arn arn:aws:personalize:us-west-2:acct-id:campaign/MovieRecommendationCampaign
```
A sample response is shown:
```
{
"campaign": {
"name": "MovieRecommendationCampaign",
"campaignArn": "arn:aws:personalize:us-west-2:acct-id:campaign/MovieRecommendationCampaign",
"solutionVersionArn": "arn:aws:personalize:us-west-2:acct-id:solution/MovieSolution/<version-id>",
"minProvisionedTPS": "10",
"creationDateTime": 1543864775.923,
"lastUpdatedDateTime": 1543864791.923,
"status": "CREATE IN_PROGRESS"
}
}
```
**Note**
Wait until the `status` shows as ACTIVE before getting recommendations from the campaign\. | https://github.com/siagholami/aws-documentation/tree/main/documents/amazon-personalize-developer-guide/doc_source/getting-started-cli.md |
0779fb53b2a0-0 | Get recommendations by running the `get-recommendations` command\. Provide the campaign ARN that was returned in the previous step\. In the request, you specify a user ID from the movie ratings dataset\. For more information about the API, see [GetRecommendations](API_RS_GetRecommendations.md)\.
**Note**
Not all recipes support the `GetRecommendations` API\. For more information, see [Choosing a Recipe](working-with-predefined-recipes.md)\.
The AWS CLI command you call in this step, `personalize-runtime`, is different than in previous steps\.
```
aws personalize-runtime get-recommendations \
--campaign-arn arn:aws:personalize:us-west-2:acct-id:campaign/MovieRecommendationCampaign \
--user-id 123
```
In response, the campaign returns a list of item recommendations \(movie IDs\) the user might like\. The list is sorted in descending order of relevance for the user\.
```
{
"itemList": [
{
"itemId": "14"
},
{
"itemId": "15"
},
{
"itemId": "275"
},
{
"itemId": "283" | https://github.com/siagholami/aws-documentation/tree/main/documents/amazon-personalize-developer-guide/doc_source/getting-started-cli.md |
0779fb53b2a0-1 | {
"itemId": "275"
},
{
"itemId": "283"
},
{
"itemId": "273"
},
...
]
}
``` | https://github.com/siagholami/aws-documentation/tree/main/documents/amazon-personalize-developer-guide/doc_source/getting-started-cli.md |
c2d06e9da1ba-0 | Provides metadata for a dataset\. | https://github.com/siagholami/aws-documentation/tree/main/documents/amazon-personalize-developer-guide/doc_source/API_Dataset.md |
8f1fb39bae97-0 | **creationDateTime** <a name="personalize-Type-Dataset-creationDateTime"></a>
The creation date and time \(in Unix time\) of the dataset\.
Type: Timestamp
Required: No
**datasetArn** <a name="personalize-Type-Dataset-datasetArn"></a>
The Amazon Resource Name \(ARN\) of the dataset that you want metadata for\.
Type: String
Length Constraints: Maximum length of 256\.
Pattern: `arn:([a-z\d-]+):personalize:.*:.*:.+`
Required: No
**datasetGroupArn** <a name="personalize-Type-Dataset-datasetGroupArn"></a>
The Amazon Resource Name \(ARN\) of the dataset group\.
Type: String
Length Constraints: Maximum length of 256\.
Pattern: `arn:([a-z\d-]+):personalize:.*:.*:.+`
Required: No
**datasetType** <a name="personalize-Type-Dataset-datasetType"></a>
One of the following values:
+ Interactions
+ Items
+ Users
Type: String
Length Constraints: Maximum length of 256\.
Required: No | https://github.com/siagholami/aws-documentation/tree/main/documents/amazon-personalize-developer-guide/doc_source/API_Dataset.md |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.