id
stringlengths
14
16
text
stringlengths
1
2.43k
source
stringlengths
99
229
7e760491b07f-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 AWS Elemental MediaConvert job templates\. + How to use a job template to create a transcoding job\. + How to list all your job templates\. + How to delete job templates\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/emc-examples-templates.md
e7c7c745c494-0
The JSON required to create a transcoding job in MediaConvert is detailed, containing a large number of settings\. You can greatly simplify job creation by saving known\-good settings in a job template that you can use to create subsequent jobs\. In this example, you use a Node\.js module to call MediaConvert to create, use, and manage job templates\. 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#createJobTemplate-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/MediaConvert.html#createJobTemplate-property) + [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#deleteJobTemplate-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/MediaConvert.html#deleteJobTemplate-property)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/emc-examples-templates.md
e7c7c745c494-1
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/MediaConvert.html#listJobTemplates-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/MediaConvert.html#listJobTemplates-property)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/emc-examples-templates.md
98f3ab5acdef-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 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-templates.md
4728edd159dd-0
Create a Node\.js module with the file name `emc_create_jobtemplate.js`\. Be sure to configure the SDK as previously shown\. Specify the parameters JSON for template creation\. You can use most of the JSON parameters from a previous successful job to specify the `Settings` values in the template\. This example uses the job settings from [Creating and Managing Transcoding Jobs in MediaConvert](emc-examples-jobs.md)\. Call the `createJobTemplate` method by creating a promise for invoking an `AWS.MediaConvert` 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: 'us-west-2'}); // Set the custom endpoint for your account AWS.config.mediaconvert = {endpoint : 'ACCOUNT_ENDPOINT'}; var params = { Category: 'YouTube Jobs', Description: 'Final production transcode', Name: 'DemoTemplate', Queue: 'JOB_QUEUE_ARN', "Settings": { "OutputGroups": [ { "Name": "File Group", "OutputGroupSettings": {
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/emc-examples-templates.md
4728edd159dd-1
"OutputGroups": [ { "Name": "File Group", "OutputGroupSettings": { "Type": "FILE_GROUP_SETTINGS", "FileGroupSettings": { "Destination": "s3://BUCKET_NAME/" } }, "Outputs": [ { "VideoDescription": { "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",
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/emc-examples-templates.md
4728edd159dd-2
"TemporalAdaptiveQuantization": "ENABLED", "FlickerAdaptiveQuantization": "DISABLED", "EntropyEncoding": "CABAC", "Bitrate": 5000000, "FramerateControl": "SPECIFIED", "RateControlMode": "CBR", "CodecProfile": "MAIN", "Telecine": "NONE", "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",
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/emc-examples-templates.md
4728edd159dd-3
"ParDenominator": 1 } }, "AfdSignaling": "NONE", "DropFrameTimecode": "ENABLED", "RespondToAfd": "NONE", "ColorMetadata": "INSERT" }, "AudioDescriptions": [ { "AudioTypeControl": "FOLLOW_INPUT", "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",
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/emc-examples-templates.md
4728edd159dd-4
"Container": "MP4", "Mp4Settings": { "CslgAtom": "INCLUDE", "FreeSpaceBox": "EXCLUDE", "MoovPlacement": "PROGRESSIVE_DOWNLOAD" } }, "NameModifier": "_1" } ] } ], "AdAvailOffset": 0, "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", } ], "TimecodeConfig": {
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/emc-examples-templates.md
4728edd159dd-5
"TimecodeSource": "EMBEDDED", } ], "TimecodeConfig": { "Source": "EMBEDDED" } } }; // Create a promise on a MediaConvert object var templatePromise = new AWS.MediaConvert({apiVersion: '2017-08-29'}).createJobTemplate(params).promise(); // Handle promise's fulfilled/rejected status templatePromise.then( function(data) { console.log("Success!", data); }, function(err) { console.log("Error", err); } ); ``` To run the example, type the following at the command line\. ``` node emc_create_jobtemplate.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_create_jobtemplate.js)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/emc-examples-templates.md
5a863d81071e-0
Create a Node\.js module with the file name `emc_template_createjob.js`\. Be sure to configure the SDK as previously shown\. Create the job creation parameters JSON, including the name of the job template to use, and the `Settings` to use that are specific to the job you're creating\. Then call the `createJobs` 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 custom endpoint for your account AWS.config.mediaconvert = {endpoint : 'ACCOUNT_ENDPOINT'}; var params = { "Queue": "QUEUE_ARN", "JobTemplate": "TEMPLATE_NAME", "Role": "ROLE_ARN", "Settings": { "Inputs": [ { "AudioSelectors": { "Audio Selector 1": { "Offset": 0, "DefaultSelection": "NOT_DEFAULT", "ProgramSelection": 1, "SelectorType": "TRACK",
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/emc-examples-templates.md
5a863d81071e-1
"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://BUCKET_NAME/FILE_NAME" } ] } }; // Create a promise on a MediaConvert object var templateJobPromise = new AWS.MediaConvert({apiVersion: '2017-08-29'}).createJob(params).promise(); // Handle promise's fulfilled/rejected status templateJobPromise.then( function(data) { console.log("Success! ", data); }, function(err) { console.log("Error", err); } ); ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/emc-examples-templates.md
5a863d81071e-2
console.log("Error", err); } ); ``` To run the example, type the following at the command line\. ``` node emc_template_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_template_createjob.js)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/emc-examples-templates.md
74ad4a5a7630-0
Create a Node\.js module with the file name `emc_listtemplates.js`\. Be sure to configure the SDK as previously shown\. Create an object to pass the request parameters for the `listTemplates` method of the `AWS.MediaConvert` client class\. Include values to determine what templates to list \(`NAME`, `CREATION DATE`, `SYSTEM`\), how many to list, and their sort order\. To call the `listTemplates` method, create a promise for invoking an MediaConvert 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: 'us-west-2'}); // Set the customer endpoint AWS.config.mediaconvert = {endpoint : 'ACCOUNT_ENDPOINT'}; var params = { ListBy: 'NAME', MaxResults: 10, Order: 'ASCENDING', }; // Create a promise on a MediaConvert object var listTemplatesPromise = new AWS.MediaConvert({apiVersion: '2017-08-29'}).listJobTemplates(params).promise(); // Handle promise's fulfilled/rejected status
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/emc-examples-templates.md
74ad4a5a7630-1
// Handle promise's fulfilled/rejected status listTemplatesPromise.then( function(data) { console.log("Success ", data); }, function(err) { console.log("Error", err); } ); ``` To run the example, type the following at the command line\. ``` node emc_listtemplates.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_template_createjob.js)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/emc-examples-templates.md
a1a2178fe720-0
Create a Node\.js module with the file name `emc_deletetemplate.js`\. Be sure to configure the SDK as previously shown\. Create an object to pass the name of the job template you want to delete as parameters for the `deleteJobTemplate` method of the `AWS.MediaConvert` client class\. To call the `deleteJobTemplate` method, create a promise for invoking an 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 = { Name: 'TEMPLATE_NAME' }; // Create a promise on a MediaConvert object var deleteTemplatePromise = new AWS.MediaConvert({apiVersion: '2017-08-29'}).deleteJobTemplate(params).promise(); // Handle promise's fulfilled/rejected status deleteTemplatePromise.then( function(data) { console.log("Success ", data); },
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/emc-examples-templates.md
a1a2178fe720-1
function(data) { console.log("Success ", data); }, function(err) { console.log("Error", err); } ); ``` To run the example, type the following at the command line\. ``` node emc_deletetemplate.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_deletetemplate.js)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/emc-examples-templates.md
ae392bc9c7d9-0
In Node\.js, you can set the maximum number of connections per origin\. If `maxSockets` is set, the low\-level HTTP client queues requests and assigns them to sockets as they become available\. This lets you set an upper bound on the number of concurrent requests to a given origin at a time\. Lowering this value can reduce the number of throttling or timeout errors received\. However, it can also increase memory usage because requests are queued until a socket becomes available\. The following example shows how to set `maxSockets` for a DynamoDB client\. ``` const dynamodb = require('aws-sdk/clients/dynamodb'); var https = require('https'); var agent = new https.Agent({ maxSockets: 25 }); var dynamodbClient = new DynamoDB({ apiVersion: '2012-08-10' httpOptions:{ agent: agent } }); ``` When using the default of `https`, the SDK takes the `maxSockets` value from the `globalAgent`\. If the `maxSockets` value is not defined or is `Infinity`, the SDK assumes a `maxSockets` value of 50\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/node-configuring-maxsockets.md
ae392bc9c7d9-1
For more information about setting `maxSockets` in Node\.js, see the [Node\.js online documentation](https://nodejs.org/dist/latest-v4.x/docs/api/http.html#http_agent_maxsockets)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/node-configuring-maxsockets.md
9a46eaaaf6f6-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 and delete IAM policies\. + How to attach and detach IAM policies from roles\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/iam-examples-policies.md
e7f73dbd4b48-0
You grant permissions to a user by creating a *policy*, which is a document that lists the actions that a user can perform and the resources those actions can affect\. Any actions or resources that are not explicitly allowed are denied by default\. Policies can be created and attached to users, groups of users, roles assumed by users, and resources\. In this example, a series of Node\.js modules are used to manage policies in IAM\. The Node\.js modules use the SDK for JavaScript to create and delete policies as well as attaching and detaching role policies using these methods of the `AWS.IAM` client class: + [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/IAM.html#createPolicy-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/IAM.html#createPolicy-property) + [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/IAM.html#getPolicy-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/IAM.html#getPolicy-property)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/iam-examples-policies.md
e7f73dbd4b48-1
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/IAM.html#listAttachedRolePolicies-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/IAM.html#listAttachedRolePolicies-property) + [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/IAM.html#attachRolePolicy-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/IAM.html#attachRolePolicy-property) + [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/IAM.html#detachRolePolicy-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/IAM.html#detachRolePolicy-property) For more information about IAM users, see [Overview of Access Management: Permissions and Policies](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction_access-management.html) in the *IAM User Guide*\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/iam-examples-policies.md
21585bd38e8e-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)\. + Create an IAM role to which you can attach policies\. For more information about creating roles, see [Creating IAM Roles](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_create.html) in the *IAM User Guide*\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/iam-examples-policies.md
d20ab01156a9-0
Create a Node\.js module with the file name `iam_createpolicy.js`\. Be sure to configure the SDK as previously shown\. To access IAM, create an `AWS.IAM` service object\. Create two JSON objects, one containing the policy document you want to create and the other containing the parameters needed to create the policy, which includes the policy JSON and the name you want to give the policy\. Be sure to stringify the policy JSON object in the parameters\. Call the `createPolicy` 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 myManagedPolicy = { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "logs:CreateLogGroup", "Resource": "RESOURCE_ARN" }, { "Effect": "Allow", "Action": [ "dynamodb:DeleteItem",
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/iam-examples-policies.md
d20ab01156a9-1
{ "Effect": "Allow", "Action": [ "dynamodb:DeleteItem", "dynamodb:GetItem", "dynamodb:PutItem", "dynamodb:Scan", "dynamodb:UpdateItem" ], "Resource": "RESOURCE_ARN" } ] }; var params = { PolicyDocument: JSON.stringify(myManagedPolicy), PolicyName: 'myDynamoDBPolicy', }; iam.createPolicy(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_createpolicy.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_createpolicy.js)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/iam-examples-policies.md
4ba798a38179-0
Create a Node\.js module with the file name `iam_getpolicy.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 retrieve a policy, which is the ARN of the policy you want to get\. Call the `getPolicy` method of the `AWS.IAM` service object\. Write the policy description 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 = { PolicyArn: 'arn:aws:iam::aws:policy/AWSLambdaExecute' }; iam.getPolicy(params, function(err, data) { if (err) { console.log("Error", err); } else { console.log("Success", data.Policy.Description); } }); ``` 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/iam-examples-policies.md
4ba798a38179-1
} }); ``` To run the example, type the following at the command line\. ``` node iam_getpolicy.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_getpolicy.js)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/iam-examples-policies.md
5b623f37fc66-0
Create a Node\.js module with the file name `iam_attachrolepolicy.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 get a list of managed IAM policies attached to a role, which consists of the name of the role\. Provide the role name as a command\-line parameter\. Call the `listAttachedRolePolicies` method of the `AWS.IAM` service object, which returns an array of managed policies to the callback function\. Check the array members to see if the policy you want to attach to the role is already attached\. If the policy is not attached, call the `attachRolePolicy` method to attach 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 paramsRoleList = { RoleName: process.argv[2] }; iam.listAttachedRolePolicies(paramsRoleList, 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-policies.md
5b623f37fc66-1
if (err) { console.log("Error", err); } else { var myRolePolicies = data.AttachedPolicies; myRolePolicies.forEach(function (val, index, array) { if (myRolePolicies[index].PolicyName === 'AmazonDynamoDBFullAccess') { console.log("AmazonDynamoDBFullAccess is already attached to this role.") process.exit(); } }); var params = { PolicyArn: 'arn:aws:iam::aws:policy/AmazonDynamoDBFullAccess', RoleName: process.argv[2] }; iam.attachRolePolicy(params, function(err, data) { if (err) { console.log("Unable to attach policy to role", err); } else { console.log("Role attached successfully"); } }); } }); ``` To run the example, type the following at the command line\. ``` node iam_attachrolepolicy.js IAM_ROLE_NAME ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/iam-examples-policies.md
2e72ce7cb531-0
Create a Node\.js module with the file name `iam_detachrolepolicy.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 get a list of managed IAM policies attached to a role, which consists of the name of the role\. Provide the role name as a command\-line parameter\. Call the `listAttachedRolePolicies` method of the `AWS.IAM` service object, which returns an array of managed policies in the callback function\. Check the array members to see if the policy you want to detach from the role is attached\. If the policy is attached, call the `detachRolePolicy` method to detach 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 paramsRoleList = { RoleName: process.argv[2] }; iam.listAttachedRolePolicies(paramsRoleList, 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-policies.md
2e72ce7cb531-1
if (err) { console.log("Error", err); } else { var myRolePolicies = data.AttachedPolicies; myRolePolicies.forEach(function (val, index, array) { if (myRolePolicies[index].PolicyName === 'AmazonDynamoDBFullAccess') { var params = { PolicyArn: 'arn:aws:iam::aws:policy/AmazonDynamoDBFullAccess', RoleName: process.argv[2] }; iam.detachRolePolicy(params, function(err, data) { if (err) { console.log("Unable to detach policy from role", err); } else { console.log("Policy detached from role successfully"); process.exit(); } }); } }); } }); ``` To run the example, type the following at the command line\. ``` node iam_detachrolepolicy.js IAM_ROLE_NAME ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/iam-examples-policies.md
f9491906c8de-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 and delete filters for log events in CloudWatch Logs\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/cloudwatch-examples-subscriptions.md
9cacf612b075-0
Subscriptions provide access to a real\-time feed of log events from CloudWatch Logs and deliver that feed to other services, such as an Amazon Kinesis stream or AWS Lambda, for custom processing, analysis, or loading to other systems\. A subscription filter defines the pattern to use for filtering which log events are delivered to your AWS resource\. In this example, a series of Node\.js modules are used to list, create, and delete a subscription filter in CloudWatch Logs\. The destination for the log events is a Lambda function\. The Node\.js modules use the SDK for JavaScript to manage subscription filters using these methods of the `CloudWatchLogs` client class: + [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CloudWatchLogs.html#putSubscriptionFilters-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CloudWatchLogs.html#putSubscriptionFilters-property) + [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CloudWatchLogs.html#describeSubscriptionFilters-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CloudWatchLogs.html#describeSubscriptionFilters-property)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/cloudwatch-examples-subscriptions.md
9cacf612b075-1
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CloudWatchLogs.html#deleteSubscriptionFilter-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CloudWatchLogs.html#deleteSubscriptionFilter-property) For more information about CloudWatch Logs subscriptions, see [Real\-time Processing of Log Data with Subscriptions](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/Subscriptions.html) in the *Amazon CloudWatch Logs User Guide*\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/cloudwatch-examples-subscriptions.md
2fe2bbf5fad5-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)\. + Create an AWS Lambda function as the destination for log events\. You will need to use the Amazon Resource Name \(ARN\) of this function\. For more information about setting up a Lambda function, see [Subscription Filters with AWS Lambda](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/SubscriptionFilters.html#LambdaFunctionExample) in the *Amazon CloudWatch Logs User Guide*\. + Create an IAM role whose policy grants permission to invoke the Lambda function you created and grants full access to CloudWatch Logs or apply the following policy to the execution role you create for the Lambda function\. 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": [
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/cloudwatch-examples-subscriptions.md
2fe2bbf5fad5-1
``` { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "logs:CreateLogGroup", "logs:CrateLogStream", "logs:PutLogEvents" ], "Resource": "arn:aws:logs:*:*:*" }, { "Effect": "Allow", "Action": [ "lambda:InvokeFunction" ], "Resource": [ "*" ] } ] } ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/cloudwatch-examples-subscriptions.md
47c6915590c9-0
Create a Node\.js module with the file name `cwl_describesubscriptionfilters.js`\. Be sure to configure the SDK as previously shown\. To access CloudWatch Logs, create an `AWS.CloudWatchLogs` service object\. Create a JSON object containing the parameters needed to describe your existing filters, including the name of the log group and the maximum number of filters you want described\. Call the `describeSubscriptionFilters` method\. ``` // Load the AWS SDK for Node.js var AWS = require('aws-sdk'); // Set the region AWS.config.update({region: 'REGION'}); // Create the CloudWatchLogs service object var cwl = new AWS.CloudWatchLogs({apiVersion: '2014-03-28'}); var params = { logGroupName: 'GROUP_NAME', limit: 5 }; cwl.describeSubscriptionFilters(params, function(err, data) { if (err) { console.log("Error", err); } else { console.log("Success", data.subscriptionFilters); } }); ``` 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-subscriptions.md
47c6915590c9-1
}); ``` To run the example, type the following at the command line\. ``` node cwl_describesubscriptionfilters.js ``` This example code can be found [here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/cloudwatch/cwl_describesubscriptionfilters.js)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/cloudwatch-examples-subscriptions.md
d985851c9c0e-0
Create a Node\.js module with the file name `cwl_putsubscriptionfilter.js`\. Be sure to configure the SDK as previously shown\. To access CloudWatch Logs, create an `AWS.CloudWatchLogs` service object\. Create a JSON object containing the parameters needed to create a filter, including the ARN of the destination Lambda function, the name of the filter, the string pattern for filtering, and the name of the log group\. Call the `putSubscriptionFilters` method\. ``` // Load the AWS SDK for Node.js var AWS = require('aws-sdk'); // Set the region AWS.config.update({region: 'REGION'}); // Create the CloudWatchLogs service object var cwl = new AWS.CloudWatchLogs({apiVersion: '2014-03-28'}); var params = { destinationArn: 'LAMBDA_FUNCTION_ARN', filterName: 'FILTER_NAME', filterPattern: 'ERROR', logGroupName: 'LOG_GROUP', }; cwl.putSubscriptionFilter(params, function(err, data) { if (err) { console.log("Error", err); } else { console.log("Success", data); }
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/cloudwatch-examples-subscriptions.md
d985851c9c0e-1
} else { console.log("Success", data); } }); ``` To run the example, type the following at the command line\. ``` node cwl_putsubscriptionfilter.js ``` This example code can be found [here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/cloudwatch/cwl_putsubscriptionfilter.js)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/cloudwatch-examples-subscriptions.md
3f070e8f2914-0
Create a Node\.js module with the file name `cwl_deletesubscriptionfilters.js`\. Be sure to configure the SDK as previously shown\. To access CloudWatch Logs, create an `AWS.CloudWatchLogs` service object\. Create a JSON object containing the parameters needed to delete a filter, including the names of the filter and the log group\. Call the `deleteSubscriptionFilters` method\. ``` // Load the AWS SDK for Node.js var AWS = require('aws-sdk'); // Set the region AWS.config.update({region: 'REGION'}); // Create the CloudWatchLogs service object var cwl = new AWS.CloudWatchLogs({apiVersion: '2014-03-28'}); var params = { filterName: 'FILTER', logGroupName: 'LOG_GROUP' }; cwl.deleteSubscriptionFilter(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\. ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/cloudwatch-examples-subscriptions.md
3f070e8f2914-1
}); ``` To run the example, type the following at the command line\. ``` node cwl_deletesubscriptionfilter.js ``` This example code can be found [here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/cloudwatch/cwl_deletesubscriptionfilter.js)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/cloudwatch-examples-subscriptions.md
7d4d8dd881a7-0
AWS Elemental MediaConvert is a file\-based video transcoding service with broadcast\-grade features\. You can use it to create assets for broadcast and for video\-on\-demand \(VOD\) delivery across the internet\. For more information, see the [https://docs.aws.amazon.com/mediaconvert/latest/ug/](https://docs.aws.amazon.com/mediaconvert/latest/ug/)\. ![\[Relationship between JavaScript environments, the SDK, and MediaConvert\]](http://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/images/code-samples-mediaconvert.png) The JavaScript API for MediaConvert is exposed through the `AWS.MediaConvert` client class\. For more information, see [Class: AWS\.MediaConvert](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/MediaConvert.html) in the API reference\. **Topics** + [Getting Your Account\-Specific Endpoint for MediaConvert](emc-examples-getendpoint.md) + [Creating and Managing Transcoding Jobs in MediaConvert](emc-examples-jobs.md) + [Using Job Templates in MediaConvert](emc-examples-templates.md)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/emc-examples.md
4392b878033b-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 obtain and display a list of Amazon S3 buckets in your account\. + How to create an Amazon S3 bucket\. + How to upload an object to a specified bucket\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-creating-buckets.md
3a1f6755698c-0
In this example, a series of Node\.js modules are used to obtain a list of existing Amazon S3 buckets, create a bucket, and upload a file to a specified bucket\. These Node\.js modules use the SDK for JavaScript to get information from and upload files to an Amazon S3 bucket using these methods of the Amazon S3 client class: + [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#listBuckets-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#listBuckets-property) + [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#createBucket-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#createBucket-property) + [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#listObjects-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#listObjects-property)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-creating-buckets.md
3a1f6755698c-1
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#upload-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#upload-property) + [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#deleteBucket-property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#deleteBucket-property)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-creating-buckets.md
e22f7950071b-0
To set up and run this example, you must first complete these tasks: + Install Node\.js\. For more information about installing Node\.js, see the [Node\.js website](https://nodejs.org)\. + Create a shared configurations file with your user credentials\. For more information about providing a shared credentials file, see [Loading Credentials in Node\.js from the Shared Credentials File](loading-node-credentials-shared.md)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-creating-buckets.md
4e94503b278d-0
Configure the SDK for JavaScript by creating a global configuration object then setting the Region for your code\. In this example, the Region is set to `us-west-2`\. ``` // Load the SDK for JavaScript var AWS = require('aws-sdk'); // Set the Region AWS.config.update({region: 'us-west-2'}); ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-creating-buckets.md
4b6e798c287a-0
Create a Node\.js module with the file name `s3_listbuckets.js`\. Make sure to configure the SDK as previously shown\. To access Amazon Simple Storage Service, create an `AWS.S3` service object\. Call the `listBuckets` method of the Amazon S3 service object to retrieve a list of your buckets\. The `data` parameter of the callback function has a `Buckets` property containing an array of maps to represent the buckets\. Display the bucket list by logging it to the console\. ``` // Load the AWS SDK for Node.js var AWS = require('aws-sdk'); // Set the region AWS.config.update({region: 'REGION'}); // Create S3 service object s3 = new AWS.S3({apiVersion: '2006-03-01'}); // Call S3 to list the buckets s3.listBuckets(function(err, data) { if (err) { console.log("Error", err); } else { console.log("Success", data.Buckets); } }); ``` To run the example, type the following at the command line\. ``` node s3_listbuckets.js ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-creating-buckets.md
4b6e798c287a-1
``` node s3_listbuckets.js ``` This sample code can be found [here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/s3/s3_listbuckets.js)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-creating-buckets.md
a20ffb2af585-0
Create a Node\.js module with the file name `s3_createbucket.js`\. Make sure to configure the SDK as previously shown\. Create an `AWS.S3` service object\. The module will take a single command\-line argument to specify a name for the new bucket\. Add a variable to hold the parameters used to call the `createBucket` method of the Amazon S3 service object, including the name for the newly created bucket\. The callback function logs the new bucket's location to the console after Amazon S3 successfully creates it\. ``` // Load the AWS SDK for Node.js var AWS = require('aws-sdk'); // Set the region AWS.config.update({region: 'REGION'}); // Create S3 service object s3 = new AWS.S3({apiVersion: '2006-03-01'}); // Create the parameters for calling createBucket var bucketParams = { Bucket : process.argv[2], ACL : 'public-read' }; // call S3 to create the bucket s3.createBucket(bucketParams, function(err, data) { if (err) { console.log("Error", err); } else { console.log("Success", data.Location); }
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-creating-buckets.md
a20ffb2af585-1
} else { console.log("Success", data.Location); } }); ``` To run the example, type the following at the command line\. ``` node s3_createbucket.js BUCKET_NAME ``` This sample code can be found [here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/s3/s3_createbucket.js)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-creating-buckets.md
20609f15a8ce-0
Create a Node\.js module with the file name `s3_upload.js`\. Make sure to configure the SDK as previously shown\. Create an `AWS.S3` service object\. The module will take two command\-line arguments, the first one to specify the destination bucket and the second to specify the file to upload\. Create a variable with the parameters needed to call the `upload` method of the Amazon S3 service object\. Provide the name of the target bucket in the `Bucket` parameter\. The `Key` parameter is set to the name of the selected file, which you can obtain using the Node\.js `path` module\. The `Body` parameter is set to the contents of the file, which you can obtain using `createReadStream` from the Node\.js `fs` module\. ``` // Load the AWS SDK for Node.js var AWS = require('aws-sdk'); // Set the region AWS.config.update({region: 'REGION'}); // Create S3 service object s3 = new AWS.S3({apiVersion: '2006-03-01'}); // call S3 to retrieve upload file to specified bucket var uploadParams = {Bucket: process.argv[2], Key: '', Body: ''}; var file = process.argv[3]; // Configure the file stream and obtain the upload parameters
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-creating-buckets.md
20609f15a8ce-1
var file = process.argv[3]; // Configure the file stream and obtain the upload parameters var fs = require('fs'); var fileStream = fs.createReadStream(file); fileStream.on('error', function(err) { console.log('File Error', err); }); uploadParams.Body = fileStream; var path = require('path'); uploadParams.Key = path.basename(file); // call S3 to retrieve upload file to specified bucket s3.upload (uploadParams, function (err, data) { if (err) { console.log("Error", err); } if (data) { console.log("Upload Success", data.Location); } }); ``` To run the example, type the following at the command line\. ``` node s3_upload.js BUCKET_NAME FILE_NAME ``` This sample code can be found [here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/s3/s3_upload.js)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-creating-buckets.md
7eb73c08c114-0
Create a Node\.js module with the file name `s3_listobjects.js`\. Make sure to configure the SDK as previously shown\. Create an `AWS.S3` service object\. Add a variable to hold the parameters used to call the `listObjects` method of the Amazon S3 service object, including the name of the bucket to read\. The callback function logs a list of objects \(files\) or a failure message\. ``` // Load the AWS SDK for Node.js var AWS = require('aws-sdk'); // Set the region AWS.config.update({region: 'REGION'}); // Create S3 service object s3 = new AWS.S3({apiVersion: '2006-03-01'}); // Create the parameters for calling listObjects var bucketParams = { Bucket : 'BUCKET_NAME', }; // Call S3 to obtain a list of the objects in the bucket s3.listObjects(bucketParams, 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\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-creating-buckets.md
7eb73c08c114-1
} }); ``` To run the example, type the following at the command line\. ``` node s3_listobjects.js ``` This sample code can be found [here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/s3/s3_listobjects.js)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-creating-buckets.md
004b4a66c8b5-0
Create a Node\.js module with the file name `s3_deletebucket.js`\. Make sure to configure the SDK as previously shown\. Create an `AWS.S3` service object\. Add a variable to hold the parameters used to call the `createBucket` method of the Amazon S3 service object, including the name of the bucket to delete\. The bucket must be empty in order to delete it\. The callback function logs a success or failure message\. ``` // Load the AWS SDK for Node.js var AWS = require('aws-sdk'); // Set the region AWS.config.update({region: 'REGION'}); // Create S3 service object s3 = new AWS.S3({apiVersion: '2006-03-01'}); // Create params for S3.deleteBucket var bucketParams = { Bucket : 'BUCKET_NAME' }; // Call S3 to delete the bucket s3.deleteBucket(bucketParams, function(err, data) { if (err) { console.log("Error", err); } else { console.log("Success", data); } }); ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-creating-buckets.md
004b4a66c8b5-1
} else { console.log("Success", data); } }); ``` To run the example, type the following at the command line\. ``` node s3_deletebucket.js ``` This sample code can be found [here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/s3/s3_deletebucket.js)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/s3-example-creating-buckets.md
1470fae001fe-0
Use the service client's `send` method to make the service call and manage asynchronous flow instead of using callbacks\. The following example shows how to get the names of your Amazon DynamoDB tables in `us-west-2`\. ``` const DDB = require('@aws-sdk/client-dynamodb') const dbClient = new DDB.DynamoDBClient({ region: 'us-west-2' }) dbClient .send(new DDB.ListTablesCommand({})) .then(response => { console.log(response.TableNames.join('\n')) }) .catch(error => { console.error(error) }) ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/using-promises.md
57096820989c-0
In some situations, your code must make multiple asynchronous calls that require action only when they have all returned successfully\. If you manage those individual asynchronous method calls with promises, you can create an additional promise that uses the `all` method\. This method fulfills this umbrella promise if and when the array of promises that you pass into the method are fulfilled\. The callback function is passed an array of the values of the promises passed to the `all` method\. In the following example, an AWS Lambda function must make three asynchronous calls to Amazon DynamoDB but can only complete after the promises for each call are fulfilled\. ``` const values = await Promise.all([firstPromise, secondPromise, thirdPromise]); console.log("Value 0 is " + values[0].toString); console.log("Value 1 is " + values[1].toString); console.log("Value 2 is " + values[2].toString); return values; ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/using-promises.md
17e1dbc491f8-0
Support for native JavaScript promises \(ECMAScript 2015\) depends on the JavaScript engine and version in which your code executes\. To help determine the support for JavaScript promises in each environment where your code needs to run, see the [ECMAScript Compatability Table](https://kangax.github.io/compat-table/es6/) on GitHub\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/using-promises.md
72481dba639d-0
In addition to the native promise implementation in ECMAScript 2015, you can also use third\-party promise libraries, including: + [bluebird](http://bluebirdjs.com) + [RSVP](https://github.com/tildeio/rsvp.js/) + [Q](https://github.com/kriskowal/q) These optional promise libraries can be useful if you need your code to run in environments that don't support the native promise implementation in ECMAScript 5 and ECMAScript 2015\. To use a third\-party promise library, set a promises dependency on the SDK by calling the `setPromisesDependency` method of the global configuration object\. In browser scripts, make sure to load the third\-party promise library before loading the SDK\. In the following example, the SDK is configured to use the implementation in the `bluebird` promise library\. ``` AWS.config.setPromisesDependency(require('bluebird')); ``` To return to using the native promise implementation of the JavaScript engine, call `setPromisesDependency` again, passing a `null` instead of a library name\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/using-promises.md
49e1f7cf32bc-0
The Amazon Web Services \(AWS\) global infrastructure is built around AWS Regions and Availability Zones\. AWS Regions provide multiple physically separated and isolated Availability Zones, which are connected with low\-latency, high\-throughput, and highly redundant networking\. With Availability Zones, you can design and operate applications and databases that automatically fail over between Availability Zones without interruption\. Availability Zones are more highly available, fault tolerant, and scalable than traditional single or multiple data center infrastructures\. For more information about AWS Regions and Availability Zones, see [AWS Global Infrastructure](https://aws.amazon.com/about-aws/global-infrastructure/)\. This AWS product or service follows the [shared responsibility model](https://aws.amazon.com/compliance/shared-responsibility-model/) through the specific Amazon Web Services \(AWS\) services it supports\. For AWS service security information, see the [AWS service security documentation page](https://docs.aws.amazon.com/security/?id=docs_gateway#aws-security) and [AWS services that are in scope of AWS compliance efforts by compliance program](https://aws.amazon.com/compliance/services-in-scope/)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/disaster-recovery-resiliency.md
84a582112a61-0
You can directly configure individual identity providers to access AWS resources using web identity federation\. AWS currently supports authenticating users using web identity federation through several identity providers: + [Login with Amazon](https://login.amazon.com) + [Facebook Login](https://www.facebook.com/about/login) + [Google Sign\-in](https://developers.google.com/identity/) You must first register your application with the providers that your application supports\. Next, create an IAM role and set up permissions for it\. The IAM role you create is then used to grant the permissions you configured for it through the respective identity provider\. For example, you can set up a role that allows users who logged in through Facebook to have read access to a specific Amazon S3 bucket you control\. After you have both an IAM role with configured privileges and an application registered with your chosen identity providers, you can set up the SDK to get credentials for the IAM role\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/loading-browser-credentials-federated-id.md
35c4288bba87-0
To begin, register an application with the identity providers you choose to support\. You will be asked to provide information that identifies your application and possibly its author\. This ensures that the identity providers know who is receiving their user information\. In each case, the identity provider will issue an application ID that you use to configure user roles\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/loading-browser-credentials-federated-id.md
906f4d83ac37-0
After you obtain the application ID from an identity provider, use the [IAM console](https://console.aws.amazon.com/iam) to create a new IAM role\. See https://docs\.aws\.amazon\.com/cognito/latest/developerguide/iam\-roles\.html for details\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/loading-browser-credentials-federated-id.md
67deaf99c025-0
Set up the login action for your application by using the identity provider's SDK\. You can download and install a JavaScript SDK from the identity provider that enables user login, using either OAuth or OpenID\. For information on how to download and set up the SDK code in your application, see the SDK documentation for your identity provider: + [Login with Amazon](https://login.amazon.com/website) + [Facebook Login](https://developers.facebook.com/docs/javascript) + [Google Sign\-in](https://developers.google.com/identity/)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/loading-browser-credentials-federated-id.md
40ff626b8a9a-0
After your application, roles, and resource permissions are configured, add the code to your application to obtain temporary credentials\. These credentials are provided through the AWS Security Token Service using web identity federation\. Users log in to the identity provider, which returns an access token\. Set up the `AWS.WebIdentityCredentials` object using the ARN for the IAM role you created for this identity provider\. ``` AWS.config.credentials = new AWS.WebIdentityCredentials({ RoleArn: 'arn:aws:iam::AWS_ACCOUNT_ID:role/WEB_IDENTITY_ROLE_NAME', ProviderId: 'PROVIDER_ID', WebIdentityToken: ACCESS_TOKEN }); ``` The value for *PROVIDER\_ID* depends on the specified identity provider: **graph\.facebook\.com** for Facebook, **www\.amazon\.com** for Amazon, and **null** for Google\. The value for *ACCESS\_TOKEN* is the access token retrieved from a successful login with the identity provider\. For more information about how to configure and retrieve access tokens for each identity provider, see the documentation from the identity provider\. Service objects that are created subsequently will have the proper credentials\. You can also create credentials before retrieving the access token\. This allows you to create service objects that depend on credentials before loading the access token\. To do this, create the credentials object without the `WebIdentityToken` parameter\. ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/loading-browser-credentials-federated-id.md
40ff626b8a9a-1
``` AWS.config.credentials = new AWS.WebIdentityCredentials({ RoleArn: 'arn:aws:iam::AWS_ACCOUNT_ID:role/WEB_IDENTITY_ROLE_NAME', ProviderId: 'PROVIDER_ID' }); ``` Then set the `WebIdentityToken` in the callback from the identity provider SDK that contains the access token\. ``` S3Client.credentials.WebIdentityToken = ACCESS_TOKEN ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/loading-browser-credentials-federated-id.md
a318c8b68ee4-0
After a service client method has been called, it returns a response object instance of an interface with the name associated with the client method\. For example, if you use the *AbcCommand* client method, the response object is of *AbcResponse* \(interface\) type\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/the-response-object.md
18b9aaab4f6b-0
The response object contains the data, as properties, returned by the service request\. In [Creating Service Client Requests](the-request-object.md), the `ListTablesCommand` command returned the table names in the `TableNames` property of the response\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/the-response-object.md
2e799f9be50b-0
If a command fails, it throws an exception\. You can handle the exception as you need\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/the-response-object.md
3f4a5a3db33c-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 access a DynamoDB table using the document client\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/dynamodb-example-document-client.md
683927aaf573-0
The DynamoDB document client simplifies working with items by abstracting the notion of attribute values\. This abstraction annotates native JavaScript types supplied as input parameters, as well as converts annotated response data to native JavaScript types\. For more information on the DynamoDB Document Client class, see [AWS\.DynamoDB\.DocumentClient](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html) in the API Reference\. For more information on programming with Amazon DynamoDB, see [Programming with DynamoDB](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Programming.html) in the *Amazon DynamoDB Developer Guide*\. In this example, you use a series of Node\.js modules to perform basic operations on a DynamoDB table using the document client\. The code uses the SDK for JavaScript to query and scan tables using these methods of the DynamoDB Document Client class: + [get](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html#get-property) + [put](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html#put-property) + [update](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html#update-property)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/dynamodb-example-document-client.md
683927aaf573-1
+ [query](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html#query-property) + [delete](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html#delete-property)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/dynamodb-example-document-client.md
7f4c40abef69-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 using the SDK for JavaScript, see [Creating and Using Tables in DynamoDB](dynamodb-examples-using-tables.md)\. You can also use the [DynamoDB console](https://console.aws.amazon.com/dynamodb/) to create a table\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/dynamodb-example-document-client.md
e74acb7a397a-0
Create a Node\.js module with the file name `ddbdoc_get.js`\. Be sure to configure the SDK as previously shown\. To access DynamoDB, create an `AWS.DynamoDB.DocumentClient` object\. Create a JSON object containing the parameters needed get an item from the table, which in this example includes the name of the table, the name of the hash key in that table, and the value of the hash key for the item you want to get\. Call the `get` method of the DynamoDB `DocumentClient` class\. ``` // Load the AWS SDK for Node.js var AWS = require('aws-sdk'); // Set the region AWS.config.update({region: 'REGION'}); // Create DynamoDB document client var docClient = new AWS.DynamoDB.DocumentClient({apiVersion: '2012-08-10'}); var params = { TableName: 'EPISODES_TABLE', Key: {'KEY_NAME': VALUE} }; docClient.get(params, function(err, data) { if (err) { console.log("Error", err); } else { console.log("Success", data.Item); } }); ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/dynamodb-example-document-client.md
e74acb7a397a-1
console.log("Success", data.Item); } }); ``` To run the example, type the following at the command line\. ``` node ddbdoc_get.js ``` This example code can be found [here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/dynamodb/ddbdoc_get.js)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/dynamodb-example-document-client.md
2d664bfa8966-0
Create a Node\.js module with the file name `ddbdoc_put.js`\. Be sure to configure the SDK as previously shown\. To access DynamoDB, create an `AWS.DynamoDB.DocumentClient` object\. Create a JSON object containing the parameters needed to write an item to the table, which in this example includes the name of the table and a description of the item to add or update that includes the hashkey and value as well as names and values for attributes to set on the item\. Call the `put` method of the DynamoDB document client\. ``` // Load the AWS SDK for Node.js var AWS = require('aws-sdk'); // Set the region AWS.config.update({region: 'REGION'}); // Create DynamoDB document client var docClient = new AWS.DynamoDB.DocumentClient({apiVersion: '2012-08-10'}); var params = { TableName: 'TABLE', Item: { 'HASHKEY': VALUE, 'ATTRIBUTE_1': 'STRING_VALUE', 'ATTRIBUTE_2': VALUE_2 } }; docClient.put(params, function(err, data) { if (err) { console.log("Error", err); } else {
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/dynamodb-example-document-client.md
2d664bfa8966-1
if (err) { console.log("Error", err); } else { console.log("Success", data); } }); ``` To run the example, type the following at the command line\. ``` node ddbdoc_put.js ``` This example code can be found [here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/dynamodb/ddbdoc_put.js)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/dynamodb-example-document-client.md
8e2fbc87954b-0
Create a Node\.js module with the file name `ddbdoc_update.js`\. Be sure to configure the SDK as previously shown\. To access DynamoDB, create an `AWS.DynamoDB.DocumentClient` object\. Create a JSON object containing the parameters needed to write an item to the table, which in this example includes the name of the table, the key of the item to update, a set of `UpdateExpressions` that define the attributes of the item to update with tokens you assign values to in the `ExpressionAttributeValues` parameters\. Call the `update` method of the DynamoDB document client\. ``` // Load the AWS SDK for Node.js var AWS = require('aws-sdk'); // Set the region AWS.config.update({region: 'REGION'}); // Create DynamoDB document client var docClient = new AWS.DynamoDB.DocumentClient({apiVersion: '2012-08-10'}); // Create variables to hold numeric key values var season = SEASON_NUMBER; var episode = EPISODES_NUMBER; var params = { TableName: 'EPISODES_TABLE', Key: { 'Season' : season, 'Episode' : episode }, UpdateExpression: 'set Title = :t, Subtitle = :s', ExpressionAttributeValues: {
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/dynamodb-example-document-client.md
8e2fbc87954b-1
UpdateExpression: 'set Title = :t, Subtitle = :s', ExpressionAttributeValues: { ':t' : 'NEW_TITLE', ':s' : 'NEW_SUBTITLE' } }; docClient.update(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 ddbdoc_update.js ``` This example code can be found [here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/dynamodb/ddbdoc_update.js)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/dynamodb-example-document-client.md
7dfa2b1e19aa-0
This example queries a table that contains episode information about a video series, returning the episode titles and subtitles of second season episodes past episode 9 that contain a specified phrase in their subtitle\. Create a Node\.js module with the file name `ddbdoc_query.js`\. Be sure to configure the SDK as previously shown\. To access DynamoDB, create an `AWS.DynamoDB.DocumentClient` object\. Create a JSON object containing the parameters needed to query the table, which in this example includes the table name, the `ExpressionAttributeValues` needed by the query, and a `KeyConditionExpression` that uses those values to define which items the query returns\. Call the `query` method of the DynamoDB document client\. ``` // Load the AWS SDK for Node.js var AWS = require('aws-sdk'); // Set the region AWS.config.update({region: 'REGION'}); // Create DynamoDB document client var docClient = new AWS.DynamoDB.DocumentClient({apiVersion: '2012-08-10'}); var params = { ExpressionAttributeValues: { ':s': 2, ':e': 9, ':topic': 'PHRASE' }, KeyConditionExpression: 'Season = :s and Episode > :e',
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/dynamodb-example-document-client.md
7dfa2b1e19aa-1
':topic': 'PHRASE' }, KeyConditionExpression: 'Season = :s and Episode > :e', FilterExpression: 'contains (Subtitle, :topic)', TableName: 'EPISODES_TABLE' }; docClient.query(params, function(err, data) { if (err) { console.log("Error", err); } else { console.log("Success", data.Items); } }); ``` To run the example, type the following at the command line\. ``` node ddbdoc_query.js ``` This example code can be found [here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/dynamodb/ddbdoc_query.js)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/dynamodb-example-document-client.md
da75091e8c81-0
Create a Node\.js module with the file name `ddbdoc_delete.js`\. Be sure to configure the SDK as previously shown\. To access DynamoDB, create an `AWS.DynamoDB.DocumentClient` object\. Create a JSON object containing the parameters needed to delete an item in the table, which in this example includes the name of the table as well as a the name and value of the hashkey of the item you want to delete\. Call the `delete` method of the DynamoDB document client\. ``` // Load the AWS SDK for Node.js var AWS = require('aws-sdk'); // Set the region AWS.config.update({region: 'REGION'}); // Create DynamoDB document client var docClient = new AWS.DynamoDB.DocumentClient({apiVersion: '2012-08-10'}); var params = { Key: { 'HASH_KEY': VALUE }, TableName: 'TABLE' }; docClient.delete(params, function(err, data) { if (err) { console.log("Error", err); } else { console.log("Success", data); } }); ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/dynamodb-example-document-client.md
da75091e8c81-1
} else { console.log("Success", data); } }); ``` To run the example, type the following at the command line\. ``` node ddbdoc_delete.js ``` This example code can be found [here on GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/dynamodb/ddbdoc_delete.js)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/dynamodb-example-document-client.md
f3948b5dc416-0
In this task, you create and populate the Amazon DynamoDB table used by the application\. ![\[Create a DynamoDB table for the tutorial application\]](http://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/images/create-ddb-table.png)![\[Create a DynamoDB table for the tutorial application\]](http://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/)![\[Create a DynamoDB table for the tutorial application\]](http://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/) The AWS Lambda function generates three random numbers, then uses those numbers as keys to look up file names stored in an Amazon DynamoDB table\. In the `slotassets.zip` archive file are two Node\.js scripts named `ddb-table-create.js` and `ddb-table-populate.js`\. Together these files create the DynamoDB table and populate it with the names of the image files in the Amazon S3 bucket\. The Lambda function exclusively provides access to the table\. Completing this portion of the application requires you to do these things: + Edit the Node\.js code used to create the DynamoDB table\. + Run the setup script that creates the DynamoDB table\. + Run the setup script, which populates the DynamoDB table with data the application expects and needs\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/using-lambda-ddb-setup.md
f3948b5dc416-1
+ Run the setup script, which populates the DynamoDB table with data the application expects and needs\. **To edit the Node\.js script that creates the DynamoDB table for the tutorial application** 1. Open `ddb-table-create.js` in the `slotassets` directory in a text editor\. 1. Find this line in the script\. `TableName: "TABLE_NAME"` Change *TABLE\_NAME* to one you choose\. Make a note of the table name\. 1. Save and close the file\. **To run the Node\.js setup script that creates the DynamoDB table** + At the command line, type the following\. `node ddb-table-create.js`
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/using-lambda-ddb-setup.md
778032f19f8c-0
The setup script `ddb-table-create.js` runs the following code\. It creates the parameters that the JSON needs to create the table\. This includes setting the table name, defining the sort key for the table \(`slotPosition`\), and defining the name of the attribute that contains the file name of one of the 16 PNG images used to display a slot wheel result\. It then calls the `createTable` method to create the table\. ``` // 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 DynamoDB service object var ddb = new AWS.DynamoDB({apiVersion: '2012-08-10'}); var tableParams = { AttributeDefinitions: [ { AttributeName: 'slotPosition', AttributeType: 'N' }, { AttributeName: 'imageFile', AttributeType: 'S' } ], KeySchema: [ { AttributeName: 'slotPosition', KeyType: 'HASH' }, { AttributeName: 'imageFile', KeyType: 'RANGE' }
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/using-lambda-ddb-setup.md
778032f19f8c-1
}, { AttributeName: 'imageFile', KeyType: 'RANGE' } ], ProvisionedThroughput: { ReadCapacityUnits: 1, WriteCapacityUnits: 1 }, TableName: 'TABLE_NAME', StreamSpecification: { StreamEnabled: false } }; ddb.createTable(tableParams, function(err, data) { if (err) { console.log("Error", err); } else { console.log("Success", data); } }); ``` Once the DynamoDB table exists, you can populate it with the items and data the application needs\. The `slotassets` directory contains t Node\.js script `ddb-table-populate.js` that automates data population for the DynamoDB table you just created\. **To run the Node\.js setup script that populates the DynamoDB table with data** 1. Open `ddb-table-populate.js` in a text editor\. 1. Find this line in the script\. `var myTable = 'TABLE_NAME';` Change *TABLE\_NAME* to the name of the table you created previously\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/using-lambda-ddb-setup.md
778032f19f8c-2
`var myTable = 'TABLE_NAME';` Change *TABLE\_NAME* to the name of the table you created previously\. 1. Save and close the file\. 1. At the command line, type the following\. `node ddb-table-populate.js`
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/using-lambda-ddb-setup.md
a47216e0dc9a-0
The setup script `ddb-table-populate.js` runs the following code\. It creates the parameters that the JSON needs to create each data item for the table\. These include a unique numeric ID value for `slotPosition` and the file name of one of the 16 PNG images of a slot wheel result for `imageFile`\. After setting the needed parameters for each possible result, the code repeatedly calls a function that executes the `putItem` method to populate items in the table\. ``` // 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 DynamoDB service object var ddb = new AWS.DynamoDB({apiVersion: '2012-08-10'}); var myTable = 'TABLE_NAME'; // Add the four results for spades var params = { TableName: myTable, Item: {'slotPosition' : {N: '0'}, 'imageFile' : {S: 'spad_a.png'} } }; post(); var params = { TableName: myTable,
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/using-lambda-ddb-setup.md
a47216e0dc9a-1
} }; post(); var params = { TableName: myTable, Item: {'slotPosition' : {N: '1'}, 'imageFile' : {S: 'spad_k.png'} } }; post(); var params = { TableName: myTable, Item: {'slotPosition' : {N: '2'}, 'imageFile' : {S: 'spad_q.png'} } }; post(); var params = { TableName: myTable, Item: {'slotPosition' : {N: '3'}, 'imageFile' : {S: 'spad_j.png'} } }; post(); // Add the four results for hearts . . . // Add the four results for diamonds . . . // Add the four results for clubs var params = { TableName: myTable, Item: {'slotPosition' : {N: '12'}, 'imageFile' : {S: 'club_a.png'} } }; post(); var params = {
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/using-lambda-ddb-setup.md
a47216e0dc9a-2
} }; post(); var params = { TableName: myTable, Item: {'slotPosition' : {N: '13'}, 'imageFile' : {S: 'club_k.png'} } }; post(); var params = { TableName: myTable, Item: {'slotPosition' : {N: '14'}, 'imageFile' : {S: 'club_q.png'} } }; post(); var params = { TableName: myTable, Item: {'slotPosition' : {N: '15'}, 'imageFile' : {S: 'club_j.png'} } }; post(); function post () { ddb.putItem(params, function(err, data) { if (err) { console.log("Error", err); } else { console.log("Success", data); } }); } ``` Click **next** to continue the tutorial\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/using-lambda-ddb-setup.md
56b2ba60b2e8-0
Web applications in browser scripts or Node\.js use of code modules creates dependencies\. These code modules can have dependencies of their own, resulting in a collection of interconnected modules that your application requires to function\. To manage dependencies, you can use a module bundler like `webpack`\. The `webpack` module bundler parses your application code, searching for `import` or `require` statements, to create bundles that contain all the assets your application needs so that the assets can be easily served through a webpage\. The SDK for JavaScript can be included in `webpack` as one of the dependencies to include in the output bundle\. ![\[Process by which webpack bundles application module dependencies into a static asset\]](http://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/images/webpack.png) For more information about `webpack`, see the [webpack module bundler](https://webpack.github.io/) on GitHub\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/webpack.md
fdc3aa4708b6-0
To install the `webpack` module bundler, you must first have npm, the Node\.js package manager, installed\. Type the following command to install the `webpack` CLI and JavaScript module\. ``` npm install --save-dev webpack ``` You may also need to install a `webpack` plugin that allows it to load JSON files\. Type the following command to install the JSON loader plugin\. ``` npm install --save-dev json-loader ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/webpack.md
26ac1bf5c0c6-0
By default, `webpack` searches for a JavaScript file named `webpack.config.js` in your project's root directory\. This file specifies your configuration options\. Here is an example of a `webpack.config.js` configuration file\. ``` // Import path for resolving file paths var path = require('path'); module.exports = { // Specify the entry point for our app. entry: [ path.join(__dirname, 'browser.js') ], // Specify the output file containing our bundled code output: { path: __dirname, filename: 'bundle.js' }, module: { /** * Tell webpack how to load 'json' files. * When webpack encounters a 'require()' statement * where a 'json' file is being imported, it will use * the json-loader. */ loaders: [ { test: /\.json$/, loaders: ['json'] } ] } } ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/webpack.md
26ac1bf5c0c6-1
loaders: ['json'] } ] } } ``` In this example, `browser.js` is specified as the entry point\. The *entry point* is the file `webpack` uses to begin searching for imported modules\. The file name of the output is specified as `bundle.js`\. This output file will contain all the JavaScript the application needs to run\. If the code specified in the entry point imports or requires other modules, such as the SDK for JavaScript, that code is bundled without needing to specify it in the configuration\. The configuration in the `json-loader` plugin that was installed earlier specifies to `webpack` how to import JSON files\. By default, `webpack` only supports JavaScript but uses loaders to add support for importing other file types\. Because the SDK for JavaScript makes extensive use of JSON files, `webpack` throws an error when generating the bundle if `json-loader` isn't included\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/webpack.md
8658b5bf852e-0
To build an application to use `webpack`, add the following to the `scripts` object in your `package.json` file\. ``` "build": "webpack" ``` Here is an example `package.json` that demonstrates adding `webpack`\. ``` { "name": "aws-webpack", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "build": "webpack" }, "author": "", "license": "ISC", "dependencies": { "aws-sdk": "^2.522.0" }, "devDependencies": { "json-loader": "^0.5.4", "webpack": "^1.13.2" } } ``` To build your application, type the following command\. ``` npm run build ``` The `webpack` module bundler then generates the JavaScript file you specified in your project's root directory\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/webpack.md
9775bdcb6abe-0
To use the bundle in a browser script, you can incorporate the bundle using a `<script>` tag, as shown in the following example\. ``` <!DOCTYPE html> <html> <head> <title>AWS SDK with webpack</title> </head> <body> <div id="list"></div> <script src="bundle.js"></script> </body> </html> ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-sdk-for-javascript-v3/doc_source/webpack.md

No dataset card yet

New: Create and edit this dataset card directly on the website!

Contribute a Dataset Card
Downloads last month
28
Add dataset card