Skip to content

Commit b771111

Browse files
committed
moved to single-consumer directory
1 parent 1503eaa commit b771111

File tree

4 files changed

+254
-0
lines changed

4 files changed

+254
-0
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
{
2+
"app": "npx ts-node --prefer-ts-exts index.ts",
3+
"watch": {
4+
"include": [
5+
"**"
6+
],
7+
"exclude": [
8+
"README.md",
9+
"cdk*.json",
10+
"**/*.d.ts",
11+
"**/*.js",
12+
"tsconfig.json",
13+
"package*.json",
14+
"yarn.lock",
15+
"node_modules",
16+
"test"
17+
]
18+
},
19+
"context": {
20+
"@aws-cdk/aws-lambda:recognizeLayerVersion": true,
21+
"@aws-cdk/core:checkSecretUsage": true,
22+
"@aws-cdk/core:target-partitions": [
23+
"aws",
24+
"aws-cn"
25+
],
26+
"@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true,
27+
"@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true,
28+
"@aws-cdk/aws-ecs:arnFormatIncludesClusterName": true,
29+
"@aws-cdk/aws-iam:minimizePolicies": true,
30+
"@aws-cdk/core:validateSnapshotRemovalPolicy": true,
31+
"@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": true,
32+
"@aws-cdk/aws-s3:createDefaultLoggingPolicy": true,
33+
"@aws-cdk/aws-sns-subscriptions:restrictSqsDescryption": true,
34+
"@aws-cdk/aws-apigateway:disableCloudWatchRole": true,
35+
"@aws-cdk/core:enablePartitionLiterals": true,
36+
"@aws-cdk/aws-events:eventsTargetQueueSameAccount": true,
37+
"@aws-cdk/aws-ecs:disableExplicitDeploymentControllerForCircuitBreaker": true,
38+
"@aws-cdk/aws-iam:importedRoleStackSafeDefaultPolicyName": true,
39+
"@aws-cdk/aws-s3:serverAccessLogsUseBucketPolicy": true,
40+
"@aws-cdk/aws-route53-patters:useCertificate": true,
41+
"@aws-cdk/customresources:installLatestAwsSdkDefault": false,
42+
"@aws-cdk/aws-rds:databaseProxyUniqueResourceName": true,
43+
"@aws-cdk/aws-codedeploy:removeAlarmsFromDeploymentGroup": true,
44+
"@aws-cdk/aws-apigateway:authorizerChangeDeploymentLogicalId": true,
45+
"@aws-cdk/aws-ec2:launchTemplateDefaultUserData": true,
46+
"@aws-cdk/aws-secretsmanager:useAttachedSecretResourcePolicyForSecretTargetAttachments": true,
47+
"@aws-cdk/aws-redshift:columnId": true,
48+
"@aws-cdk/aws-stepfunctions-tasks:enableEmrServicePolicyV2": true,
49+
"@aws-cdk/aws-ec2:restrictDefaultSecurityGroup": true,
50+
"@aws-cdk/aws-apigateway:requestValidatorUniqueId": true,
51+
"@aws-cdk/aws-kms:aliasNameRef": true,
52+
"@aws-cdk/aws-autoscaling:generateLaunchTemplateInsteadOfLaunchConfig": true,
53+
"@aws-cdk/core:includePrefixInUniqueNameGeneration": true,
54+
"@aws-cdk/aws-efs:denyAnonymousAccess": true,
55+
"@aws-cdk/aws-opensearchservice:enableOpensearchMultiAzWithStandby": true,
56+
"@aws-cdk/aws-lambda-nodejs:useLatestRuntimeVersion": true,
57+
"@aws-cdk/aws-efs:mountTargetOrderInsensitiveLogicalId": true,
58+
"@aws-cdk/aws-rds:auroraClusterChangeScopeOfInstanceParameterGroupWithEachParameters": true,
59+
"@aws-cdk/aws-appsync:useArnForSourceApiAssociationIdentifier": true,
60+
"@aws-cdk/aws-rds:preventRenderingDeprecatedCredentials": true,
61+
"@aws-cdk/aws-codepipeline-actions:useNewDefaultBranchForCodeCommitSource": true,
62+
"@aws-cdk/aws-cloudwatch-actions:changeLambdaPermissionLogicalIdForLambdaAction": true,
63+
"@aws-cdk/aws-codepipeline:crossAccountKeysDefaultValueToFalse": true,
64+
"@aws-cdk/aws-codepipeline:defaultPipelineTypeToV2": true,
65+
"@aws-cdk/aws-kms:reduceCrossAccountRegionPolicyScope": true,
66+
"@aws-cdk/aws-eks:nodegroupNameAttribute": true,
67+
"@aws-cdk/aws-ec2:ebsDefaultGp3Volume": true,
68+
"@aws-cdk/aws-ecs:removeDefaultDeploymentAlarm": true,
69+
"@aws-cdk/custom-resources:logApiResponseDataPropertyTrueDefault": false,
70+
"@aws-cdk/aws-s3:keepNotificationInImportedBucket": false,
71+
"@aws-cdk/aws-ecs:enableImdsBlockingDeprecatedFeature": false,
72+
"@aws-cdk/aws-ecs:disableEcsImdsBlocking": true,
73+
"@aws-cdk/aws-ecs:reduceEc2FargateCloudWatchPermissions": true,
74+
"@aws-cdk/aws-dynamodb:resourcePolicyPerReplica": true,
75+
"@aws-cdk/aws-ec2:ec2SumTImeoutEnabled": true,
76+
"@aws-cdk/aws-appsync:appSyncGraphQLAPIScopeLambdaPermission": true,
77+
"@aws-cdk/aws-rds:setCorrectValueForDatabaseInstanceReadReplicaInstanceResourceId": true,
78+
"@aws-cdk/core:cfnIncludeRejectComplexResourceUpdateCreatePolicyIntrinsics": true,
79+
"@aws-cdk/aws-lambda-nodejs:sdkV3ExcludeSmithyPackages": true,
80+
"@aws-cdk/aws-stepfunctions-tasks:fixRunEcsTaskPolicy": true,
81+
"@aws-cdk/aws-ec2:bastionHostUseAmazonLinux2023ByDefault": true,
82+
"@aws-cdk/aws-route53-targets:userPoolDomainNameMethodWithoutCustomResource": true,
83+
"@aws-cdk/aws-elasticloadbalancingV2:albDualstackWithoutPublicIpv4SecurityGroupRulesDefault": true,
84+
"@aws-cdk/aws-iam:oidcRejectUnauthorizedConnections": true,
85+
"@aws-cdk/core:enableAdditionalMetadataCollection": true,
86+
"@aws-cdk/aws-lambda:createNewPoliciesWithAddToRolePolicy": true,
87+
"@aws-cdk/aws-s3:setUniqueReplicationRoleName": true,
88+
"@aws-cdk/aws-events:requireEventBusPolicySid": true
89+
}
90+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
import * as cdk from 'aws-cdk-lib';
2+
import * as targets from 'aws-cdk-lib/aws-events-targets';
3+
import { EventBus, Rule } from 'aws-cdk-lib/aws-events';
4+
import { LogGroup } from 'aws-cdk-lib/aws-logs';
5+
import { CloudWatchLogGroup } from 'aws-cdk-lib/aws-events-targets';
6+
import { AccountPrincipal, Effect, PolicyStatement } from 'aws-cdk-lib/aws-iam';
7+
import { Construct } from 'constructs';
8+
9+
export interface producerStackProps extends cdk.StackProps {
10+
readonly appName: string;
11+
readonly consumerAccountId: string;
12+
}
13+
14+
export interface consumerStackProps extends cdk.StackProps {
15+
readonly appName: string;
16+
readonly producerAccountId: string;
17+
}
18+
19+
export class producerStack extends cdk.Stack {
20+
constructor(scope: Construct, id: string, props: producerStackProps) {
21+
super(scope, id, props);
22+
23+
// Create the EventBus
24+
const producerEventBus = new EventBus(this, `${props.appName}-producer-event-bus`);
25+
26+
// Create rule to forward events to consumer account
27+
const rule = new Rule(this, `${props.appName}-forward-to-consumer-rule`, {
28+
eventBus: producerEventBus,
29+
eventPattern: {
30+
// Define your event pattern here
31+
source: ['com.myapp.events'],
32+
},
33+
});
34+
35+
// Add target to forward to consumer account's event bus
36+
rule.addTarget(new targets.EventBus(
37+
EventBus.fromEventBusArn(
38+
this,
39+
'ConsumerEventBus',
40+
`arn:aws:events:${cdk.Stack.of(this).region}:${props.consumerAccountId}:event-bus/default`
41+
)
42+
));
43+
44+
// Optional: Add CloudWatch target for monitoring
45+
rule.addTarget(new targets.CloudWatchLogGroup(
46+
new LogGroup(this, `${props.appName}-producer-logs`)
47+
));
48+
}
49+
}
50+
51+
export class consumerStack extends cdk.Stack {
52+
constructor(scope: Construct, id: string, props: consumerStackProps) {
53+
super(scope, id, props);
54+
55+
// Create or reference the consumer event bus
56+
const consumerEventBus = new EventBus(this, `${props.appName}-consumer-event-bus`);
57+
58+
// Add policy to allow producer account to put events
59+
consumerEventBus.addToResourcePolicy(new PolicyStatement({
60+
sid: 'allowProducerAccount',
61+
effect: Effect.ALLOW,
62+
principals: [new AccountPrincipal(props.producerAccountId)],
63+
actions: ['events:PutEvents'],
64+
resources: [consumerEventBus.eventBusArn]
65+
}));
66+
67+
// Create consumer rules
68+
const consumerRule = new Rule(this, `${props.appName}-consumer-rule`, {
69+
eventBus: consumerEventBus,
70+
eventPattern: {
71+
// Define more specific filtering here
72+
source: ['com.myapp.events'],
73+
detail: {
74+
type: ['specific-event-type']
75+
}
76+
}
77+
});
78+
79+
// Add target (e.g., CloudWatch)
80+
consumerRule.addTarget(new CloudWatchLogGroup(
81+
new LogGroup(this, `${props.appName}-consumer-logs`)
82+
));
83+
}
84+
}
85+
86+
const app = new cdk.App();
87+
const appName = 'eventbridge-mesh';
88+
const region = 'us-east-1';
89+
const producerAccountId = '123510061335';
90+
const consumerAccountId = '737719307477';
91+
92+
new producerStack(app, `${appName}-producer-stack`, {
93+
env: {
94+
account: producerAccountId,
95+
region: region,
96+
},
97+
appName,
98+
consumerAccountId,
99+
});
100+
101+
new consumerStack(app, `${appName}-consumer-stack`, {
102+
env: {
103+
account: consumerAccountId,
104+
region: region,
105+
},
106+
appName,
107+
producerAccountId,
108+
});
109+
110+
app.synth();
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "eventbridge-mesh",
3+
"version": "0.1.0",
4+
"scripts": {
5+
"build": "tsc",
6+
"watch": "tsc -w",
7+
"test": "jest",
8+
"cdk": "cdk"
9+
},
10+
"devDependencies": {
11+
"@types/jest": "^29.5.14",
12+
"@types/node": "22.7.9",
13+
"jest": "^29.7.0",
14+
"ts-jest": "^29.2.5",
15+
"aws-cdk": "2.1007.0",
16+
"ts-node": "^10.9.2",
17+
"typescript": "~5.6.3"
18+
},
19+
"dependencies": {
20+
"aws-cdk-lib": "2.186.0",
21+
"constructs": "^10.0.0"
22+
}
23+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES2020",
4+
"module": "commonjs",
5+
"lib": [
6+
"es2020",
7+
"dom"
8+
],
9+
"declaration": true,
10+
"strict": true,
11+
"noImplicitAny": true,
12+
"strictNullChecks": true,
13+
"noImplicitThis": true,
14+
"alwaysStrict": true,
15+
"noUnusedLocals": false,
16+
"noUnusedParameters": false,
17+
"noImplicitReturns": true,
18+
"noFallthroughCasesInSwitch": false,
19+
"inlineSourceMap": true,
20+
"inlineSources": true,
21+
"experimentalDecorators": true,
22+
"strictPropertyInitialization": false,
23+
"typeRoots": [
24+
"./node_modules/@types"
25+
]
26+
},
27+
"exclude": [
28+
"node_modules",
29+
"cdk.out"
30+
]
31+
}

0 commit comments

Comments
 (0)