AWS code-library documentation change
Summary
Added JavaScript SDK v2 example code for AWS Entity Resolution scenario including resource creation, workflow execution, and cleanup processes
Security assessment
The changes add example code for normal service operations without addressing vulnerabilities or security weaknesses. While the code handles IAM roles and resource permissions through CloudFormation, this is standard service integration rather than security-specific documentation. The tagResourceCommand shows basic resource tagging but doesn't introduce new security controls.
Diff
diff --git a/code-library/latest/ug/entityresolution_example_entityresolution_Scenario_section.md b/code-library/latest/ug/entityresolution_example_entityresolution_Scenario_section.md index 4d8957226..ad34a4d9d 100644 --- a//code-library/latest/ug/entityresolution_example_entityresolution_Scenario_section.md +++ b//code-library/latest/ug/entityresolution_example_entityresolution_Scenario_section.md @@ -9 +9 @@ There are more AWS SDK examples available in the [AWS Doc SDK Examples](https:// -The following code example shows how to: +The following code examples show how to: @@ -1189,0 +1190,706 @@ A wrapper class for AWS Entity Resolution SDK methods. +JavaScript + + +**SDK for JavaScript (v2)** + + +###### Note + +There's more on GitHub. Find the complete example and learn how to set up and run in the [AWS Code Examples Repository](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/javav2/example_code/entityresolution#code-examples). + +Run an interactive scenario demonstrating AWS Entity Resolution features. + + + import { + Scenario, + ScenarioAction, + ScenarioInput, + ScenarioOutput, + } from "@aws-doc-sdk-examples/lib/scenario/index.js"; + import { + CloudFormationClient, + CreateStackCommand, + DeleteStackCommand, + DescribeStacksCommand, + waitUntilStackExists, + waitUntilStackCreateComplete, + } from "@aws-sdk/client-cloudformation"; + import { + EntityResolutionClient, + CreateSchemaMappingCommand, + CreateMatchingWorkflowCommand, + GetMatchingJobCommand, + StartMatchingJobCommand, + GetSchemaMappingCommand, + ListSchemaMappingsCommand, + TagResourceCommand, + DeleteMatchingWorkflowCommand, + DeleteSchemaMappingCommand, + ConflictException, + ValidationException, + } from "@aws-sdk/client-entityresolution"; + import { + DeleteObjectsCommand, + DeleteBucketCommand, + PutObjectCommand, + S3Client, + ListObjectsCommand, + } from "@aws-sdk/client-s3"; + import { wait } from "@aws-doc-sdk-examples/lib/utils/util-timers.js"; + + import { readFile } from "node:fs/promises"; + import { parseArgs } from "node:util"; + import { readFileSync } from "node:fs"; + import { fileURLToPath } from "node:url"; + import { dirname } from "node:path"; + + const __filename = fileURLToPath(import.meta.url); + const __dirname = dirname(__filename); + const stackName = `${data.inputs.entityResolutionStack}`; + + /*The inputs for this example can be edited in the ../input.json.*/ + import data from "../inputs.json" with { type: "json" }; + const skipWhenErrors = (state) => state.errors.length > 0; + /** + * Used repeatedly to have the user press enter. + * @type {ScenarioInput} + */ + /* v8 ignore next 3 */ + const pressEnter = new ScenarioInput("continue", "Press Enter to continue", { + type: "input", + verbose: "false", + skipWhen: skipWhenErrors, + }); + + const region = "eu-west-1"; + + const entityResolutionClient = new EntityResolutionClient({ region: region }); + const cloudFormationClient = new CloudFormationClient({ region: region }); + const s3Client = new S3Client({ region: region }); + + const greet = new ScenarioOutput( + "greet", + "AWS Entity Resolution is a fully-managed machine learning service provided by " + + "Amazon Web Services (AWS) that helps organizations extract, link, and " + + "organize information from multiple data sources. It leverages natural " + + "language processing and deep learning models to identify and resolve " + + "entities, such as people, places, organizations, and products, " + + "across structured and unstructured data.\n" + + "\n" + + "With Entity Resolution, customers can build robust data integration " + + "pipelines to combine and reconcile data from multiple systems, databases, " + + "and documents. The service can handle ambiguous, incomplete, or conflicting " + + "information, and provide a unified view of entities and their relationships. " + + "This can be particularly valuable in applications such as customer 360, " + + "fraud detection, supply chain management, and knowledge management, where " + + "accurate entity identification is crucial.\n" + + "\n" + + "The `EntityResolutionAsyncClient` interface in the AWS SDK for Java 2.x " + + "provides a set of methods to programmatically interact with the AWS Entity " + + "Resolution service. This allows developers to automate the entity extraction, " + + "linking, and deduplication process as part of their data processing workflows. " + + "With Entity Resolution, organizations can unlock the value of their data, " + + "improve decision-making, and enhance customer experiences by having a reliable, " + + "comprehensive view of their key entities.", + + { header: true }, + ); + const displayBuildCloudFormationStack = new ScenarioOutput( + "displayBuildCloudFormationStack", + "To prepare the AWS resources needed for this scenario application, the next step uploads " + + "a CloudFormation template whose resulting stack creates the following resources:\n" + + "- An AWS Glue Data Catalog table \n" + + "- An AWS IAM role \n" + + "- An AWS S3 bucket \n" + + "- An AWS Entity Resolution Schema \n" + + "It can take a couple minutes for the Stack to finish creating the resources.", + ); + + const sdkBuildCloudFormationStack = new ScenarioAction( + "sdkBuildCloudFormationStack", + async (/** @type {State} */ state) => { + try { + const data = readFileSync( + `${__dirname}/../../../../resources/cfn/entity-resolution-basics/entity-resolution-basics-template.yml`, + "utf8", + ); + await cloudFormationClient.send( + new CreateStackCommand({ + StackName: stackName, + TemplateBody: data, + Capabilities: ["CAPABILITY_IAM"], + }), + ); + await waitUntilStackExists( + { client: cloudFormationClient }, + { StackName: stackName }, + ); + await waitUntilStackCreateComplete( + { client: cloudFormationClient }, + { StackName: stackName }, + ); + const stack = await cloudFormationClient.send( + new DescribeStacksCommand({ + StackName: stackName, + }), + ); + + state.entityResolutionRole = stack.Stacks[0].Outputs[1]; + state.jsonGlueTable = stack.Stacks[0].Outputs[2]; + state.CSVGlueTable = stack.Stacks[0].Outputs[3]; + state.glueDataBucket = stack.Stacks[0].Outputs[0]; + state.stackName = stack.StackName; + console.log(state.glueDataBucket); + console.log( + `The ARN of the EntityResolution Role is ${state.entityResolutionRole.OutputValue}`, + ); + console.log( + `The ARN of the Json Glue Table is ${state.jsonGlueTable.OutputValue}`, + ); + console.log( + `The ARN of the CSV Glue Table is ${state.CSVGlueTable.OutputValue}`, + ); + console.log( + `The name of the Glue Data Bucket is ${state.glueDataBucket.OutputValue}\n`, + ); + } catch (caught) { + console.error(caught.message); + throw caught; + } + try { + console.log( + `Uploading the following JSON in ../data.json to the ${state.glueDataBucket.OutputValue} S3 bucket...`, + ); + const bucketName = state.glueDataBucket.OutputValue; + + const putObjectParams = { + Bucket: bucketName, + Key: "jsonData/data.json", + Body: await readFileSync( + `${__dirname}/../../../../javascriptv3/example_code/entityresolution/data.json`, + ), + }; + const command = new PutObjectCommand(putObjectParams); + const response = await s3Client.send(command); + console.log( + `../data.json file data uploaded to the ${state.glueDataBucket.OutputValue} S3 bucket.\n`, + ); + } catch (caught) { + console.error(caught.message); + throw caught; + } + try {