Looking for how to use this in your app?See Frontend Libraries →
Amazon Data Firehose
Use the AWS Cloud Development Kit (AWS CDK) to create an Amazon Data Firehose delivery stream and grant your app the permissions it needs. For more on adding custom AWS resources to your Amplify backend, see Custom resources.
Set up a Firehose delivery stream
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);If you are not using the CDK, ensure your authenticated IAM role has the firehose:PutRecordBatch permission on your target delivery stream:
{ "Version": "2012-10-17", "Statement": [{ "Effect": "Allow", "Action": "firehose:PutRecordBatch", "Resource": "arn:aws:firehose:<region>:<account-id>:deliverystream/<stream-name>" }]}For more information, see the Amazon Data Firehose Developer Documentation.
Next steps
Use the Firehose client to stream data from your app.