aws-amplify / aws-amplify/docs
Event Bridge example with L2 Rule construct instead of L1 Cfn
- Dominant language
- MDX
- Stars
- 506
- Forks
- 1.1k
- Avg merge
- 3h 14m
- Merged PRs (30d)
- 1
Description
### Environment information
```plain text
npx ampx info
System:
OS: macOS 14
CPU: (8) arm64 Apple M2
Binaries:
Node: 20.15.0 - ~/.n/bin/node
Yarn: 4.3.1 - ~/.n/bin/yarn
npm: 10.7.0 - ~/.n/bin/npm
pnpm: undefined - undefined
NPM Packages:
@aws-amplify/backend: 1.0.4
@aws-amplify/backend-cli: 1.1.0
aws-amplify: 6.3.8
aws-cdk: 2.147.2
aws-cdk-lib: 2.147.2
typescript: 5.5.2
AWS environment variables:
AWS_STS_REGIONAL_ENDPOINTS = regional
AWS_NODEJS_CONNECTION_REUSE_ENABLED = 1
AWS_SDK_LOAD_CONFIG = 1
No CDK environment variables
```
### Description
Regarding EventBridge example for data sources
https://docs.amplify.aws/react/build-a-backend/data/custom-business-logic/connect-eventbridge-datasource/
I'm trying to setup this example with L2 construct Rule (https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_events.Rule.html)
This is the class, where api is `backend.data.resources.graphqlApi`
```
export class FileSearchEventBus extends Construct {
constructor(scope: Construct, id: string, api: IGraphqlApi) {
super(scope, id)
const eventBus = new EventBus(this, "filesearch", {})
api.addEventBridgeDataSource("EventBridgeSrc", eventBus)
console.debug("EventBridgeSrc is added")
const policyStatement = new PolicyStatement({
effect: Effect.ALLOW,
actions: ["appsync:GraphQL"],
resources: [`${api.arn}/types/Mutation/*`]
})
const eventBusRole = new Role(this, "AppSyncInvokeRole", {
assumedBy: new ServicePrincipal("events.amazonaws.com"),
inlinePolicies: {
PolicyStatement: new PolicyDocument({
statements: [policyStatement]
})
}
})
new Rule(this, "FileSearch", {
eventBus: eventBus,
ruleName: "broadcastFileSearchUpdates",
eventPattern: {
source: ["amplify.filesearch"],
detailType: ["FileSearchChange"],
detail: {
fileId: [{ exists: true }],
status: ["PENDING", "ATTACHED", "DETACHED"],
message: [{ exists: true }]
}
},
targets: [
new AppSync(api, {
variables: RuleTargetInput.fromObject({
fileId: EventField.fromPath("$.detail.fileId"),
status: EventField.fromPath("$.detail.status"),
message: EventField.fromPath("$.detail.message")
}),
graphQLOperation: `
mutation PublishFileSearchFromEventBridge(
$fileId: String!
$status: String!
$message: String!
) {
publishFileSearchFromEventBridge(fileId: $fileId, status: $status, message: $message) {
fileId
status
message
}
}
`,
eventRole: eventBusRole
})
]
})
}
}
```
I define data backend as this
```
export const data = defineData({
name: "data",
schema,
authorizationModes: {
defaultAuthorizationMode: "userPool"
}
})
```
The stack breaks.
`Error: You must have AWS_IAM authorization mode enabled on your API to configure an AppSync target`
This is the check on construct here, https://github.com/aws/aws-cdk/blob/v2.147.3/packages/aws-cdk-lib/aws-events-targets/lib/appsync.ts#L49
The modes on backend's app sync is empty.
Question: is it still possible to use L2 for the example you have? It seems to support all props. Was this the reason you've use Cnf?
Contributor guide
Assessment
This issue has not been assessed yet.