-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add another example and map additional resources (#178)
Adds tests for additional resources and adds mappings for very common resources that do not yet have CCAPI support. - AWS::SQS::QueuePolicy - AWS::SNS::TopicPolicy ``` aws-native:sns:Subscription aws-native:sqs:Queue aws-native:sns:Topic aws-native:sns:Subscription aws-native:iam:Role aws-native:lambda:Function aws-native:events:EventBus aws-native:events:Rule aws-native:sns:Topic ```
- Loading branch information
Showing
14 changed files
with
7,355 additions
and
1,020 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -116,3 +116,5 @@ dist | |
|
||
test-reports/ | ||
lib/ | ||
|
||
**/cdk.out |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
name: pulumi-aws-eventbridge-sns | ||
runtime: nodejs | ||
description: Eventbridge SNS example for CDK |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { EventBridgeClient, PutEventsCommand } from '@aws-sdk/client-eventbridge'; | ||
let client: EventBridgeClient; | ||
|
||
export const handler = async function (event, context) { | ||
if (!client) { | ||
client = new EventBridgeClient(); | ||
} | ||
|
||
const eventBusName = process.env.BUS_NAME; | ||
await client.send( | ||
new PutEventsCommand({ | ||
Entries: [ | ||
{ | ||
// Event envelope fields | ||
Source: 'custom.myATMapp', | ||
EventBusName: eventBusName, | ||
DetailType: 'transaction', | ||
Time: new Date(), | ||
// Main event body | ||
Detail: JSON.stringify({ | ||
action: 'withdrawal', | ||
location: 'MA-BOS-01', | ||
amount: 300, | ||
result: 'approved', | ||
transactionId: '123456', | ||
cardPresent: true, | ||
partnerBank: 'Example Bank', | ||
remainingFunds: 722.34, | ||
}), | ||
}, | ||
{ | ||
// Event envelope fields | ||
Source: 'custom.myATMapp', | ||
EventBusName: eventBusName, | ||
DetailType: 'transaction', | ||
Time: new Date(), | ||
|
||
// Main event body | ||
Detail: JSON.stringify({ | ||
action: 'withdrawal', | ||
location: 'NY-NYC-002', | ||
amount: 60, | ||
result: 'denied', | ||
transactionId: '123458', | ||
cardPresent: true, | ||
remainingFunds: 5.77, | ||
}), | ||
}, | ||
], | ||
}), | ||
); | ||
|
||
return { | ||
statusCode: 200, | ||
}; | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import * as pulumicdk from '@pulumi/cdk'; | ||
import { | ||
aws_events, | ||
aws_events_targets, | ||
aws_lambda, | ||
aws_lambda_nodejs, | ||
aws_sns, | ||
aws_sns_subscriptions, | ||
aws_sqs, | ||
} from 'aws-cdk-lib'; | ||
|
||
class EventBridgeSnsStack extends pulumicdk.Stack { | ||
constructor(id: string) { | ||
super(id); | ||
|
||
const eventBus = new aws_events.EventBus(this, 'Bus'); | ||
const handler = new aws_lambda_nodejs.NodejsFunction(this, 'handler', { | ||
runtime: aws_lambda.Runtime.NODEJS_LATEST, | ||
environment: { | ||
BUS_NAME: eventBus.eventBusName, | ||
}, | ||
}); | ||
eventBus.grantPutEventsTo(handler); | ||
|
||
// create an archive so we can replay events later | ||
eventBus.archive('archive', { | ||
eventPattern: { | ||
source: ['custom.myATMapp'], | ||
}, | ||
}); | ||
|
||
const approvedRule = new aws_events.Rule(this, 'approved-rule', { | ||
eventBus, | ||
description: 'Approved transactions', | ||
eventPattern: { | ||
source: ['custom.myATMapp'], | ||
detailType: ['transaction'], | ||
detail: { | ||
result: ['approved'], | ||
}, | ||
}, | ||
}); | ||
|
||
const approvedTopic = new aws_sns.Topic(this, 'approved-topic'); | ||
|
||
approvedRule.addTarget(new aws_events_targets.SnsTopic(approvedTopic)); | ||
|
||
const approvedQueue = new aws_sqs.Queue(this, 'approved-queue'); | ||
approvedTopic.addSubscription( | ||
new aws_sns_subscriptions.SqsSubscription(approvedQueue, { | ||
rawMessageDelivery: true, | ||
}), | ||
); | ||
|
||
const deniedRule = new aws_events.Rule(this, 'denied-rule', { | ||
eventBus, | ||
description: 'Denied transactions', | ||
eventPattern: { | ||
source: ['custom.myATMapp'], | ||
detailType: ['transaction'], | ||
detail: { | ||
result: ['denied'], | ||
}, | ||
}, | ||
}); | ||
const deniedTopic = new aws_sns.Topic(this, 'denied-topic'); | ||
deniedRule.addTarget(new aws_events_targets.SnsTopic(deniedTopic)); | ||
|
||
const deniedQueue = new aws_sqs.Queue(this, 'denied-queue'); | ||
deniedTopic.addSubscription( | ||
new aws_sns_subscriptions.SqsSubscription(deniedQueue, { | ||
rawMessageDelivery: true, | ||
}), | ||
); | ||
this.synth(); | ||
} | ||
} | ||
|
||
new EventBridgeSnsStack('eventbridge-sns-stack'); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "pulumi-aws-cdk", | ||
"devDependencies": { | ||
"@types/node": "^20.0.0" | ||
}, | ||
"dependencies": { | ||
"@aws-sdk/client-eventbridge": "^3.678.0", | ||
"@pulumi/aws-native": "^1.0.0", | ||
"@pulumi/cdk": "^0.5.0", | ||
"@pulumi/pulumi": "^3.0.0", | ||
"aws-cdk-lib": "2.149.0", | ||
"constructs": "10.3.0", | ||
"esbuild": "^0.24.0" | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"compilerOptions": { | ||
"strict": true, | ||
"outDir": "bin", | ||
"target": "es2016", | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"sourceMap": true, | ||
"experimentalDecorators": true, | ||
"pretty": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"noImplicitReturns": true, | ||
"forceConsistentCasingInFileNames": true | ||
}, | ||
"files": [ | ||
"index.ts" | ||
] | ||
} |
This file contains 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
Oops, something went wrong.