Skip to content

Commit

Permalink
Add another example and map additional resources (#178)
Browse files Browse the repository at this point in the history
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
corymhall authored Oct 25, 2024
1 parent 72108f4 commit 1df8353
Show file tree
Hide file tree
Showing 14 changed files with 7,355 additions and 1,020 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,5 @@ dist

test-reports/
lib/

**/cdk.out
3 changes: 3 additions & 0 deletions examples/eventbridge-sns/Pulumi.yaml
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
56 changes: 56 additions & 0 deletions examples/eventbridge-sns/index.handler.ts
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,
};
};
79 changes: 79 additions & 0 deletions examples/eventbridge-sns/index.ts
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');
15 changes: 15 additions & 0 deletions examples/eventbridge-sns/package.json
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"
}
}
18 changes: 18 additions & 0 deletions examples/eventbridge-sns/tsconfig.json
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"
]
}
9 changes: 9 additions & 0 deletions examples/examples_nodejs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,15 @@ func TestCloudFront(t *testing.T) {
integration.ProgramTest(t, &test)
}

func TestEventBridgeSNS(t *testing.T) {
test := getJSBaseOptions(t).
With(integration.ProgramTestOptions{
Dir: filepath.Join(getCwd(t), "eventbridge-sns"),
})

integration.ProgramTest(t, &test)
}

func TestAPIWebsocketLambdaDynamoDB(t *testing.T) {
test := getJSBaseOptions(t).
With(integration.ProgramTestOptions{
Expand Down
Loading

0 comments on commit 1df8353

Please sign in to comment.