Skip to content

Commit

Permalink
fix(AWS EventBridge): Ensure proper support for deadLetterConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
pgrzesik committed Sep 30, 2021
1 parent abbb18d commit 77cdf54
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 35 deletions.
7 changes: 3 additions & 4 deletions docs/providers/aws/events/event-bridge.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,9 @@ functions:
source:
- saas.external
deadLetterConfig:
targetArn:
Fn::GetAtt:
- QueueName
- Arn
Fn::GetAtt:
- QueueName
- Arn
```

## Adding a retry policy to an event rule
Expand Down
7 changes: 7 additions & 0 deletions docs/providers/aws/guide/serverless.yml.md
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,13 @@ functions:
inputPathsMap:
eventTime: '$.time'
inputTemplate: '{"time": <eventTime>, "key1": "value1"}'
retryPolicy:
maximumEventAge: 3600
maximumRetryAttempts: 3
deadLetterConfig:
Fn::GetAtt:
- QueueName
- Arn
- cloudFront:
eventType: viewer-response
includeBody: true
Expand Down
38 changes: 14 additions & 24 deletions lib/plugins/aws/package/compile/events/eventBridge/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,7 @@ class AwsCompileEventBridgeEvents {
},
},
},
deadLetterConfig: {
type: 'object',
properties: {
targetArn: {
$ref: '#/definitions/awsArn',
},
},
additionalProperties: false,
},
deadLetterConfig: { $ref: '#/definitions/awsArn' },
},
anyOf: [{ required: ['pattern'] }, { required: ['schedule'] }],
});
Expand Down Expand Up @@ -193,7 +185,7 @@ class AwsCompileEventBridgeEvents {
);
}
DeadLetterConfig = {
TargetArn: DeadLetterConfig.targetArn,
Arn: DeadLetterConfig,
};
}

Expand Down Expand Up @@ -509,35 +501,33 @@ class AwsCompileEventBridgeEvents {
}

configureTarget({ target, Input, InputPath, InputTransformer, RetryPolicy, DeadLetterConfig }) {
if (Input) {
if (RetryPolicy) {
target = Object.assign(target, {
Input: JSON.stringify(Input),
RetryPolicy,
});
return target;
}
if (InputPath) {

if (DeadLetterConfig) {
target = Object.assign(target, {
InputPath,
DeadLetterConfig,
});
return target;
}
if (InputTransformer) {

if (Input) {
target = Object.assign(target, {
InputTransformer,
Input: JSON.stringify(Input),
});
return target;
}

if (RetryPolicy) {
if (InputPath) {
target = Object.assign(target, {
RetryPolicy,
InputPath,
});
return target;
}

if (DeadLetterConfig) {
if (InputTransformer) {
target = Object.assign(target, {
DeadLetterConfig,
InputTransformer,
});
return target;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,7 @@ describe('EventBridgeEvents', () => {
{
eventBridge: {
deadLetterConfig: {
targetArn: {
'Fn::GetAtt': ['not-supported', 'Arn'],
},
'Fn::GetAtt': ['not-supported', 'Arn'],
},
pattern: {
source: ['aws.something'],
Expand Down Expand Up @@ -399,9 +397,7 @@ describe('EventBridgeEvents', () => {
};

const deadLetterConfig = {
targetArn: {
'Fn::GetAtt': ['test', 'Arn'],
},
'Fn::GetAtt': ['test', 'Arn'],
};

const getRuleResourceEndingWith = (resources, ending) =>
Expand Down Expand Up @@ -550,7 +546,7 @@ describe('EventBridgeEvents', () => {
it('should support deadLetterConfig configuration', () => {
const deadLetterConfigRuleTarget = getRuleResourceEndingWith(cfResources, '7').Properties
.Targets[0];
expect(deadLetterConfigRuleTarget.DeadLetterConfig).to.have.property('TargetArn');
expect(deadLetterConfigRuleTarget.DeadLetterConfig).to.have.property('Arn');
});

it('should create a rule that depends on created EventBus', () => {
Expand Down

0 comments on commit 77cdf54

Please sign in to comment.