|
| 1 | +import { getCustomStaticPath } from '@/utils/getCustomStaticPath'; |
| 2 | + |
| 3 | +export const meta = { |
| 4 | + title: 'Kinesis Data Streams', |
| 5 | + description: 'Set up an Amazon Kinesis Data Stream and configure IAM permissions for the Amplify Kinesis Data Streams client.', |
| 6 | + platforms: [ |
| 7 | + 'android', |
| 8 | + 'flutter', |
| 9 | + 'swift' |
| 10 | + ], |
| 11 | +}; |
| 12 | + |
| 13 | +export const getStaticPaths = async () => { |
| 14 | + return getCustomStaticPath(meta.platforms); |
| 15 | +}; |
| 16 | + |
| 17 | +export function getStaticProps(context) { |
| 18 | + return { |
| 19 | + props: { |
| 20 | + platform: context.params.platform, |
| 21 | + meta |
| 22 | + } |
| 23 | + }; |
| 24 | +} |
| 25 | + |
| 26 | +Use the [AWS Cloud Development Kit (AWS CDK)](https://docs.aws.amazon.com/cdk/latest/guide/home.html) to create an [Amazon Kinesis Data Stream](https://aws.amazon.com/kinesis/data-streams/) and grant your app the permissions it needs. For more on adding custom AWS resources to your Amplify backend, see [Custom resources](/[platform]/build-a-backend/add-aws-services/custom-resources/). |
| 27 | + |
| 28 | +## Set up a Kinesis stream |
| 29 | + |
| 30 | +```ts title="amplify/backend.ts" |
| 31 | +import { defineBackend } from "@aws-amplify/backend"; |
| 32 | +import { auth } from "./auth/resource"; |
| 33 | +import { data } from "./data/resource"; |
| 34 | +import { Policy, PolicyStatement } from "aws-cdk-lib/aws-iam"; |
| 35 | +import { Stream } from "aws-cdk-lib/aws-kinesis"; |
| 36 | +import { Stack } from "aws-cdk-lib/core"; |
| 37 | + |
| 38 | +const backend = defineBackend({ |
| 39 | + auth, |
| 40 | + data, |
| 41 | +}); |
| 42 | + |
| 43 | +const kinesisStack = backend.createStack("kinesis-stack"); |
| 44 | + |
| 45 | +// Create a Kinesis stream |
| 46 | +const kinesisStream = new Stream(kinesisStack, "KinesisStream", { |
| 47 | + streamName: "myKinesisStream", |
| 48 | + shardCount: 1, |
| 49 | +}); |
| 50 | + |
| 51 | +// Grant PutRecords permission to authenticated users |
| 52 | +const kinesisPolicy = new Policy(kinesisStack, "KinesisPolicy", { |
| 53 | + statements: [ |
| 54 | + new PolicyStatement({ |
| 55 | + actions: ["kinesis:PutRecords"], |
| 56 | + resources: [kinesisStream.streamArn], |
| 57 | + }), |
| 58 | + ], |
| 59 | +}); |
| 60 | + |
| 61 | +backend.auth.resources.authenticatedUserIamRole.attachInlinePolicy(kinesisPolicy); |
| 62 | +``` |
| 63 | + |
| 64 | +If you are not using the CDK, ensure your authenticated IAM role has the `kinesis:PutRecords` permission on your target stream: |
| 65 | + |
| 66 | +```json |
| 67 | +{ |
| 68 | + "Version": "2012-10-17", |
| 69 | + "Statement": [{ |
| 70 | + "Effect": "Allow", |
| 71 | + "Action": "kinesis:PutRecords", |
| 72 | + "Resource": "arn:aws:kinesis:<region>:<account-id>:stream/<stream-name>" |
| 73 | + }] |
| 74 | +} |
| 75 | +``` |
| 76 | + |
| 77 | +For more information, see the [Amazon Kinesis Developer Documentation](https://docs.aws.amazon.com/streams/latest/dev/learning-kinesis-module-one-iam.html). |
| 78 | + |
| 79 | +## Next steps |
| 80 | + |
| 81 | +Use the [Kinesis Data Streams client](/[platform]/frontend/analytics/kinesis/) to stream data from your app. |
0 commit comments