Name:
interface
Value:
Amplify has re-imagined the way frontend developers build fullstack applications. Develop and deploy without the hassle.

Choose your framework/language

Gen1 DocsLegacy

Page updated Feb 22, 2025

Predictions の設定

Predictions を有効にするには、Cognito Identity Pool のロールに適切な IAM ポリシーを設定して、適切な機能を使用できるようにする必要があります。さらに、addOutput メソッドを使用して、カスタム Predictions リソースに期待される出力設定をパッチする必要があります。

注: 以下の例では、サポートされているすべての ML 機能を有効にするようにポリシーを設定しています。ユースケースに関連するアクションとリソースのみを含めてください。 詳細については、Amazon TranslateAmazon PollyAmazon TranscribeAmazon RekognitionAmazon Textract、および Amazon Comprehend のドキュメントをご覧ください。

amplify/backend.ts
import { PolicyStatement } from "aws-cdk-lib/aws-iam";
import { defineBackend } from "@aws-amplify/backend";
import { auth } from "./auth/resource";
const backend = defineBackend({
auth,
});
// Configure a policy for the required use case.
// The actions included below cover all supported ML capabilities
backend.auth.resources.unauthenticatedUserIamRole.addToPrincipalPolicy(
new PolicyStatement({
actions: [
"translate:TranslateText",
"polly:SynthesizeSpeech",
"transcribe:StartStreamTranscriptionWebSocket",
"comprehend:DetectSentiment",
"comprehend:DetectEntities",
"comprehend:DetectDominantLanguage",
"comprehend:DetectSyntax",
"comprehend:DetectKeyPhrases",
"rekognition:DetectFaces",
"rekognition:RecognizeCelebrities",
"rekognition:DetectLabels",
"rekognition:DetectModerationLabels",
"rekognition:DetectText",
"rekognition:DetectLabel",
"rekognition:SearchFacesByImage",
"textract:AnalyzeDocument",
"textract:DetectDocumentText",
"textract:GetDocumentAnalysis",
"textract:StartDocumentAnalysis",
"textract:StartDocumentTextDetection",
],
resources: ["*"],
})
);
backend.addOutput({
custom: {
Predictions: {
convert: {
translateText: {
defaults: {
sourceLanguage: "en",
targetLanguage: "es",
},
proxy: false,
region: backend.auth.stack.region,
},
speechGenerator: {
defaults: {
voiceId: "Ivy",
},
proxy: false,
region: backend.auth.stack.region,
},
transcription: {
defaults: {
language: "en-US",
},
proxy: false,
region: backend.auth.stack.region,
},
},
identify: {
identifyEntities: {
defaults: {
collectionId: "default",
maxEntities: 10,
},
celebrityDetectionEnabled: true,
proxy: false,
region: backend.auth.stack.region,
},
identifyLabels: {
defaults: {
type: "ALL",
},
proxy: false,
region: backend.auth.stack.region,
},
identifyText: {
defaults: {
format: "ALL",
},
proxy: false,
region: backend.auth.stack.region,
},
},
interpret: {
interpretText: {
defaults: {
type: "ALL",
},
proxy: false,
region: backend.auth.stack.region,
},
},
},
},
});

Amplify ライブラリのインストール

Predictions 機能を使用する Amplify ライブラリをインストールするには、プロジェクトのルート フォルダで以下のコマンドを実行してください:

Terminal
npm add aws-amplify @aws-amplify/predictions

フロントエンドの設定

設定ファイルをインポートしてアプリに読み込みます。Amplify 設定ステップは、アプリのルート エントリ ポイント (React や Angular の場合は main.ts など) に追加することをお勧めします。

src/main.ts
import { Amplify } from "aws-amplify";
import { parseAmplifyConfig } from "aws-amplify/utils";
import outputs from '../amplify_outputs.json';
const amplifyConfig = parseAmplifyConfig(outputs);
Amplify.configure({
...amplifyConfig,
Predictions: outputs.custom.Predictions,
});