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

Page updated Mar 26, 2026

ストリーミング分析データ

AWS will end support for Amazon Pinpoint on October 30, 2026,, and is no longer accepting any new users as of May 20 (see the linked doc). The guidance is to use AWS End User Messaging for push notifications and SMS, Amazon Simple Email Service for sending emails, Amazon Connect for campaigns, journeys, endpoints, and engagement analytics. Pinpoint recommends Amazon Kinesis for event collection and mobile analytics.

Amazon Kinesis分析プロバイダーを使用すると、分析データをKinesisストリームに送信して、リアルタイム処理を行うことができます。

Kinesisストリームの設定

以下は、AWS Cloud Development Kit (AWS CDK)を使用してAmazon Kinesisで動作するAnalyticsリソースを作成する例です。

amplify/backend.ts
import { auth } from "./auth/resource";
import { data } from "./data/resource";
import { Policy, PolicyStatement } from "aws-cdk-lib/aws-iam";
import { Stream } from "aws-cdk-lib/aws-kinesis";
import { Stack } from "aws-cdk-lib/core";
const backend = defineBackend({
auth,
data,
// additional resources
});
// create a new stack for the Kinesis stream
const kinesisStack = backend.createStack("kinesis-stack");
// create a new Kinesis stream with one shard
const kinesisStream = new Stream(kinesisStack, "KinesisStream", {
streamName: "myKinesisStream",
shardCount: 1,
});
// create a new policy to allow PutRecords to the Kinesis stream
const kinesisPolicy = new Policy(kinesisStack, "KinesisPolicy", {
statements: [
new PolicyStatement({
actions: ["kinesis:PutRecords"],
resources: [kinesisStream.streamArn],
}),
],
});
// apply the policy to the authenticated and unauthenticated roles
backend.auth.resources.authenticatedUserIamRole.attachInlinePolicy(kinesisPolicy);
backend.auth.resources.unauthenticatedUserIamRole.attachInlinePolicy(kinesisPolicy);

インストールと設定

CLIを使用しなかった場合は、kinesis:PutRecordsIAM権限を設定していることを確認してください。

Amazon Kinesis用のIAMポリシーの例:

{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": "kinesis:PutRecords",
"Resource": "arn:aws:kinesis:<your-aws-region>:<your-aws-account-id>:stream/<your-stream-name>" // replace the template fields
}]
}

詳細はAmazon Kinesis開発者向けドキュメントをご覧ください。

Kinesisを設定します:

src/index.js
// Configure the plugin after adding it to the Analytics module
import { Amplify } from 'aws-amplify';
import { parseAmplifyConfig } from "aws-amplify/utils";
import outputs from '../amplify_outputs.json';
const amplifyConfig = parseAmplifyConfig(outputs);
Amplify.configure({
...amplifyConfig,
Analytics: {
Kinesis: {
// REQUIRED - Amazon Kinesis service region
region: 'us-east-1',
// OPTIONAL - The buffer size for events in number of items.
bufferSize: 1000,
// OPTIONAL - The number of events to be deleted from the buffer when flushed.
flushSize: 100,
// OPTIONAL - The interval in milliseconds to perform a buffer check and flush if necessary.
flushInterval: 5000, // 5s
// OPTIONAL - The limit for failed recording retries.
resendLimit: 5
}
}
});

データのストリーミング

標準のrecord()メソッドを使用して、Kinesisストリームにデータを送信できます:

src/index.js
import { record } from 'aws-amplify/analytics/kinesis';
record({
data: {
// The data blob to put into the record
},
partitionKey: 'myPartitionKey',
streamName: 'myKinesisStream'
});

イベントのフラッシュ

記録されたイベントはバッファに保存され、定期的にリモートサーバーに送信されます*(flushIntervalオプションで調整できます)*。必要に応じて、'flushEvents' APIを使用してバッファからすべてのイベントを手動でクリアすることができます。

src/index.js
import { flushEvents } from 'aws-amplify/analytics/kinesis';
flushEvents();