Created
July 4, 2024 13:44
-
-
Save adleroliveira/d5fda5a12c0cf1412b4a7f4a1490bfcf to your computer and use it in GitHub Desktop.
Amplify Gen 2 circular dependency workaround
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mport { defineBackend } from "@aws-amplify/backend"; | |
import { EventSourceMapping, StartingPosition } from "aws-cdk-lib/aws-lambda"; | |
import { DynamoEventSource } from "aws-cdk-lib/aws-lambda-event-sources"; | |
import { auth } from "./auth/resource"; | |
import { data } from "./data/resource"; | |
import { myDynamoDBFunction } from "./functions/dynamoDB-function/resource"; | |
import { Effect, Policy, PolicyStatement } from "aws-cdk-lib/aws-iam"; | |
import { Stack } from "aws-cdk-lib"; | |
const backend = defineBackend({ | |
auth, | |
data, | |
myDynamoDBFunction, | |
}); | |
const todoTable = backend.data.resources.tables["Todo"]; | |
backend.myDynamoDBFunction.resources.lambda.role?.attachInlinePolicy( | |
new Policy(Stack.of(todoTable), "DynamoDBPolicy", { | |
statements: [ | |
new PolicyStatement({ | |
effect: Effect.ALLOW, | |
actions: [ | |
"dynamodb:DescribeStream", | |
"dynamodb:GetRecords", | |
"dynamodb:GetShardIterator", | |
"dynamodb:ListStreams", | |
], | |
resources: ["*"], | |
}), | |
], | |
}) | |
); | |
new EventSourceMapping(Stack.of(todoTable), "test", { | |
target: backend.myDynamoDBFunction.resources.lambda, | |
eventSourceArn: todoTable.tableStreamArn, | |
startingPosition: StartingPosition.LATEST, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment