Looking for how to use this in your app?See Frontend Libraries →
Amazon Data Firehose
AWS Cloud Development Kit (AWS CDK) を使用して Amazon Data Firehose 配信ストリームを作成し、アプリに必要な権限を付与します。Amplify バックエンドへのカスタム AWS リソースの追加の詳細については、カスタムリソースを参照してください。
Firehose 配信ストリームをセットアップする
amplify/backend.ts
import { defineBackend } from "@aws-amplify/backend";import { auth } from "./auth/resource";import { data } from "./data/resource";import { storage } from "./storage/resource";import { CfnDeliveryStream } from "aws-cdk-lib/aws-kinesisfirehose";import { Stack } from "aws-cdk-lib/core";import { Policy, PolicyStatement, Role, ServicePrincipal,} from "aws-cdk-lib/aws-iam";
const backend = defineBackend({ auth, data, storage,});
const firehoseStack = backend.createStack("firehose-stack");
// Access the S3 bucket resourceconst s3Bucket = backend.storage.resources.bucket;
// Create a new IAM role for the Firehoseconst firehoseRole = new Role(firehoseStack, "FirehoseRole", { assumedBy: new ServicePrincipal("firehose.amazonaws.com"),});
// Grant the Firehose role read/write permissions to the S3 buckets3Bucket.grantReadWrite(firehoseRole);
// Create a Firehose delivery streamconst myFirehose = new CfnDeliveryStream(firehoseStack, "MyFirehose", { deliveryStreamType: "DirectPut", s3DestinationConfiguration: { bucketArn: s3Bucket.bucketArn, roleArn: firehoseRole.roleArn, }, deliveryStreamName: "myFirehose",});
// Grant PutRecordBatch permission to authenticated usersconst firehosePolicy = new Policy(firehoseStack, "FirehosePolicy", { statements: [ new PolicyStatement({ actions: ["firehose:PutRecordBatch"], resources: [myFirehose.attrArn], }), ],});
backend.auth.resources.authenticatedUserIamRole.attachInlinePolicy(firehosePolicy);CDK を使用していない場合は、認証済み IAM ロールが対象の配信ストリームに対して firehose:PutRecordBatch 権限を持つことを確認してください。
{ "Version": "2012-10-17", "Statement": [{ "Effect": "Allow", "Action": "firehose:PutRecordBatch", "Resource": "arn:aws:firehose:<region>:<account-id>:deliverystream/<stream-name>" }]}詳細については、Amazon Data Firehose デベロッパーガイドを参照してください。
次のステップ
Firehose クライアントを使用してアプリからデータをストリーミングします。