Skip to content
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

Adding InputTransformer Property #3338

Merged
merged 3 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class EventBridgeRuleEventProperties(BaseModel):
RetryPolicy: Optional[PassThroughProp] = eventbridgeruleeventproperties("RetryPolicy")
Target: Optional[EventBridgeRuleTarget] = eventbridgeruleeventproperties("Target")
RuleName: Optional[PassThroughProp] = eventbridgeruleeventproperties("RuleName")
InputTransformer: Optional[PassThroughProp] # TODO: add docs


class EventBridgeRuleEvent(BaseModel):
Expand Down
5 changes: 5 additions & 0 deletions samtranslator/model/stepfunctions/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ class CloudWatchEvent(EventSource):
"RetryPolicy": PropertyType(False, IS_DICT),
"State": PropertyType(False, IS_STR),
"Target": Property(False, IS_DICT),
"InputTransformer": PropertyType(False, IS_DICT),
}

EventBusName: Optional[PassThrough]
Expand All @@ -204,6 +205,7 @@ class CloudWatchEvent(EventSource):
RetryPolicy: Optional[PassThrough]
State: Optional[PassThrough]
Target: Optional[PassThrough]
InputTransformer: Optional[PassThrough]

@cw_timer(prefix=SFN_EVETSOURCE_METRIC_PREFIX)
def to_cloudformation(self, resource, **kwargs): # type: ignore[no-untyped-def]
Expand Down Expand Up @@ -273,6 +275,9 @@ def _construct_target(self, resource, role, dead_letter_queue_arn=None): # type
if self.RetryPolicy is not None:
target["RetryPolicy"] = self.RetryPolicy

if self.InputTransformer is not None:
target["InputTransformer"] = self.InputTransformer

return target


Expand Down
3 changes: 3 additions & 0 deletions samtranslator/schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -254477,6 +254477,9 @@
"markdownDescription": "When you don't want to pass the entire matched event to the target, use the `InputPath` property to describe which part of the event to pass\\. \n*Type*: String \n*Required*: No \n*AWS CloudFormation compatibility*: This property is passed directly to the [`InputPath`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-target.html#cfn-events-rule-target-inputpath) property of an `AWS::Events::Rule Target` resource\\.",
"title": "InputPath"
},
"InputTransformer": {
"$ref": "#/definitions/PassThroughProp"
},
"Pattern": {
"allOf": [
{
Expand Down
3 changes: 3 additions & 0 deletions schema_source/sam.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -7660,6 +7660,9 @@
"markdownDescription": "When you don't want to pass the entire matched event to the target, use the `InputPath` property to describe which part of the event to pass\\. \n*Type*: String \n*Required*: No \n*AWS CloudFormation compatibility*: This property is passed directly to the [`InputPath`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-target.html#cfn-events-rule-target-inputpath) property of an `AWS::Events::Rule Target` resource\\.",
"title": "InputPath"
},
"InputTransformer": {
"$ref": "#/definitions/PassThroughProp"
},
"Pattern": {
"allOf": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
Resources:
StateMachine:
Type: AWS::Serverless::StateMachine
Properties:
Name: !Sub ${AWS::StackName}-StateMachine
Definition:
Comment: A Hello World example of the Amazon States Language using Pass states
StartAt: Hello
States:
Hello:
Type: Pass
Result: Hello
Next: World
World:
Type: Pass
Result: World
End: true
Policies:
- Version: '2012-10-17'
Statement:
- Effect: Deny
Action: '*'
Resource: '*'
Events:
EventBridgeEvent:
Type: EventBridgeRule
Properties:
EventBusName: default
Pattern:
source:
- aws.s3
detail-type:
- Object Created
detail:
bucket:
name:
- abc
object:
key:
- xyz
InputTransformer:
InputPathsMap:
bucket: $.detail.bucket.name
key: $.detail.object.key
InputTemplate: '{"bucket": <bucket>, "key": <key>}'
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
{
"Resources": {
"StateMachine": {
"Properties": {
"DefinitionString": {
"Fn::Join": [
"\n",
[
"{",
" \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",",
" \"StartAt\": \"Hello\",",
" \"States\": {",
" \"Hello\": {",
" \"Next\": \"World\",",
" \"Result\": \"Hello\",",
" \"Type\": \"Pass\"",
" },",
" \"World\": {",
" \"End\": true,",
" \"Result\": \"World\",",
" \"Type\": \"Pass\"",
" }",
" }",
"}"
]
]
},
"RoleArn": {
"Fn::GetAtt": [
"StateMachineRole",
"Arn"
]
},
"StateMachineName": {
"Fn::Sub": "${AWS::StackName}-StateMachine"
},
"Tags": [
{
"Key": "stateMachine:createdBy",
"Value": "SAM"
}
]
},
"Type": "AWS::StepFunctions::StateMachine"
},
"StateMachineEventBridgeEvent": {
"Properties": {
"EventBusName": "default",
"EventPattern": {
"detail": {
"bucket": {
"name": [
"abc"
]
},
"object": {
"key": [
"xyz"
]
}
},
"detail-type": [
"Object Created"
],
"source": [
"aws.s3"
]
},
"Targets": [
{
"Arn": {
"Ref": "StateMachine"
},
"Id": "StateMachineEventBridgeEventStepFunctionsTarget",
"InputTransformer": {
"InputPathsMap": {
"bucket": "$.detail.bucket.name",
"key": "$.detail.object.key"
},
"InputTemplate": "{\"bucket\": <bucket>, \"key\": <key>}"
},
"RoleArn": {
"Fn::GetAtt": [
"StateMachineEventBridgeEventRole",
"Arn"
]
}
}
]
},
"Type": "AWS::Events::Rule"
},
"StateMachineEventBridgeEventRole": {
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": [
"sts:AssumeRole"
],
"Effect": "Allow",
"Principal": {
"Service": [
"events.amazonaws.com"
]
}
}
],
"Version": "2012-10-17"
},
"Policies": [
{
"PolicyDocument": {
"Statement": [
{
"Action": "states:StartExecution",
"Effect": "Allow",
"Resource": {
"Ref": "StateMachine"
}
}
]
},
"PolicyName": "StateMachineEventBridgeEventRoleStartExecutionPolicy"
}
]
},
"Type": "AWS::IAM::Role"
},
"StateMachineRole": {
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": [
"sts:AssumeRole"
],
"Effect": "Allow",
"Principal": {
"Service": [
"states.amazonaws.com"
]
}
}
],
"Version": "2012-10-17"
},
"ManagedPolicyArns": [],
"Policies": [
{
"PolicyDocument": {
"Statement": [
{
"Action": "*",
"Effect": "Deny",
"Resource": "*"
}
],
"Version": "2012-10-17"
},
"PolicyName": "StateMachineRolePolicy0"
}
],
"Tags": [
{
"Key": "stateMachine:createdBy",
"Value": "SAM"
}
]
},
"Type": "AWS::IAM::Role"
}
}
}
Loading