-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(iotevents): add IoT Events input L2 Construct #17847
Changes from 2 commits
3e069e9
4cda347
0f15502
a9ddebb
d1adc50
ed80896
fb25883
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
export * from './input'; | ||
|
||
// AWS::IoTEvents CloudFormation Resources: | ||
export * from './iotevents.generated'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { Resource } from '@aws-cdk/core'; | ||
import { Construct } from 'constructs'; | ||
import { CfnInput } from './iotevents.generated'; | ||
|
||
/** | ||
* Properties for defining an AWS IoT Events input | ||
*/ | ||
export interface InputProps { | ||
/** | ||
* The name of the input | ||
* | ||
* @default xxx | ||
*/ | ||
readonly inputName?: string, | ||
|
||
/** | ||
* An expression that specifies an attribute-value pair in a JSON structure. | ||
* Use this to specify an attribute from the JSON payload that is made available | ||
* by the input. Inputs are derived from messages sent to AWS IoT Events (BatchPutMessage). | ||
* Each such message contains a JSON payload. The attribute (and its paired value) | ||
* specified here are available for use in the condition expressions used by detectors. | ||
*/ | ||
readonly attributeJsonPaths: string[]; | ||
} | ||
|
||
/** | ||
* Defines an AWS IoT Events input in this stack. | ||
*/ | ||
export class Input extends Resource { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like we're missing the |
||
/** | ||
* The name of the input | ||
* @attribute | ||
*/ | ||
public readonly inputName: string; | ||
|
||
constructor(scope: Construct, id: string, props: InputProps) { | ||
super(scope, id, { | ||
physicalName: props.inputName, | ||
}); | ||
|
||
const resource = new CfnInput(this, 'Resource', { | ||
inputName: this.physicalName, | ||
inputDefinition: { | ||
attributes: props.attributeJsonPaths.map(path => ({ jsonPath: path })), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As you said,
|
||
}, | ||
}); | ||
|
||
this.inputName = this.getResourceNameAttribute(resource.ref); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { Template } from '@aws-cdk/assertions'; | ||
import * as cdk from '@aws-cdk/core'; | ||
import * as iotevents from '../lib'; | ||
|
||
test('Default property', () => { | ||
const stack = new cdk.Stack(); | ||
|
||
// WHEN | ||
new iotevents.Input(stack, 'MyInput', { | ||
attributeJsonPaths: ['payload.temperature'], | ||
}); | ||
|
||
// THEN | ||
Template.fromStack(stack).hasResourceProperties('AWS::IoTEvents::Input', { | ||
InputDefinition: { | ||
Attributes: [{ JsonPath: 'payload.temperature' }], | ||
}, | ||
}); | ||
}); | ||
|
||
test('can get input name', () => { | ||
const stack = new cdk.Stack(); | ||
// GIVEN | ||
const input = new iotevents.Input(stack, 'MyInput', { | ||
attributeJsonPaths: ['payload.temperature'], | ||
}); | ||
|
||
// WHEN | ||
new cdk.CfnResource(stack, 'Res', { | ||
type: 'Test::Resource', | ||
properties: { | ||
InputName: input.inputName, | ||
}, | ||
}); | ||
|
||
// THEN | ||
Template.fromStack(stack).hasResourceProperties('Test::Resource', { | ||
InputName: { Ref: 'MyInput08947B23' }, | ||
}); | ||
}); | ||
|
||
test('can set physical name', () => { | ||
const stack = new cdk.Stack(); | ||
|
||
// WHEN | ||
new iotevents.Input(stack, 'MyInput', { | ||
inputName: 'test_input', | ||
attributeJsonPaths: ['payload.temperature'], | ||
}); | ||
|
||
// THEN | ||
Template.fromStack(stack).hasResourceProperties('AWS::IoTEvents::Input', { | ||
InputName: 'test_input', | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"Resources": { | ||
"MyInput08947B23": { | ||
"Type": "AWS::IoTEvents::Input", | ||
"Properties": { | ||
"InputDefinition": { | ||
"Attributes": [ | ||
{ | ||
"JsonPath": "payload.temperature" | ||
} | ||
] | ||
}, | ||
"InputName": "test_input" | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import * as cdk from '@aws-cdk/core'; | ||
import * as iotevents from '../lib'; | ||
|
||
const app = new cdk.App(); | ||
|
||
class TestStack extends cdk.Stack { | ||
constructor(scope: cdk.App, id: string, props?: cdk.StackProps) { | ||
super(scope, id, props); | ||
|
||
new iotevents.Input(this, 'MyInput', { | ||
inputName: 'test_input', | ||
attributeJsonPaths: ['payload.temperature'], | ||
}); | ||
} | ||
} | ||
|
||
new TestStack(app, 'test-stack'); | ||
app.synth(); |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙇🏻