A Pulumi package for creating and managing Amazon Web Services (AWS) cloud resources with infrastructure-as-code.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Amazon Comprehend is a natural language processing (NLP) service that uses machine learning to find insights and relationships in text.
import * as aws from "@pulumi/aws";Amazon Comprehend provides pre-trained and custom ML models for text analysis.
Determine positive, negative, neutral, or mixed sentiment.
const sentimentRole = new aws.iam.Role("comprehend-role", {
assumeRolePolicy: JSON.stringify({
Version: "2012-10-17",
Statement: [{
Action: "sts:AssumeRole",
Effect: "Allow",
Principal: {
Service: "comprehend.amazonaws.com",
},
}],
}),
});
const sentimentPolicy = new aws.iam.Policy("comprehend-s3", {
policy: JSON.stringify({
Version: "2012-10-17",
Statement: [{
Effect: "Allow",
Action: [
"s3:GetObject",
"s3:ListBucket",
"s3:PutObject",
],
Resource: [
bucket.arn,
pulumi.interpolate`${bucket.arn}/*`,
],
}],
}),
});
new aws.iam.RolePolicyAttachment("attach", {
role: sentimentRole.name,
policyArn: sentimentPolicy.arn,
});Identify people, places, organizations, dates, and more.
Extract key phrases and topics from text.
Detect the dominant language in text.
Train custom models for document classification.
const documentClassifierRole = new aws.iam.Role("classifier-role", {
assumeRolePolicy: JSON.stringify({
Version: "2012-10-17",
Statement: [{
Action: "sts:AssumeRole",
Effect: "Allow",
Principal: {
Service: "comprehend.amazonaws.com",
},
}],
}),
});Train models to recognize custom entities specific to your domain.
const comprehendLambda = new aws.lambda.Function("text-analysis", {
runtime: "python3.11",
handler: "index.handler",
role: lambdaRole.arn,
code: new pulumi.asset.AssetArchive({
"index.py": new pulumi.asset.StringAsset(`
import boto3
import json
comprehend = boto3.client('comprehend')
def handler(event, context):
text = event['text']
# Detect sentiment
sentiment = comprehend.detect_sentiment(
Text=text,
LanguageCode='en'
)
# Extract entities
entities = comprehend.detect_entities(
Text=text,
LanguageCode='en'
)
return {
'sentiment': sentiment,
'entities': entities
}
`),
}),
});Process large volumes of documents.
const batchRole = new aws.iam.Role("batch-role", {
assumeRolePolicy: JSON.stringify({
Version: "2012-10-17",
Statement: [{
Action: "sts:AssumeRole",
Effect: "Allow",
Principal: {
Service: "comprehend.amazonaws.com",
},
}],
}),
});Install with Tessl CLI
npx tessl i tessl/npm-pulumi--aws@7.16.0