Skip to content

Commit

Permalink
feat(AWS EventBridge): Adjust deprecation of deployment method
Browse files Browse the repository at this point in the history
  • Loading branch information
pgrzesik committed Oct 22, 2021
1 parent 889e1be commit bf62b7c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
4 changes: 3 additions & 1 deletion docs/deprecations.md
Expand Up @@ -188,10 +188,12 @@ Starting with v3.0.0, `http.request.schema` property will be replaced by `http.r

Deprecation code: `AWS_EVENT_BRIDGE_CUSTOM_RESOURCE`

Starting with v3.0.0 AWS EventBridge lambda event triggers and all associated EventBridge resources will be deployed using native CloudFormation resources instead of a custom resource that used a lambda to deploy them via the AWS SDK/API.
Starting with v3.0.0, AWS EventBridge lambda event triggers and all associated EventBridge resources will be, by default, deployed using native CloudFormation resources instead of a custom resource that used a lambda to deploy them via the AWS SDK/API.

Adapt to this behavior now by setting `provider.eventBridge.useCloudFormation: true`.

If you want to keep using the old deployment method for your AWS EventBridge resources, set `provider.eventBridge.useCloudFormation: false` instead.

<a name="NEW_VARIABLES_RESOLVER"><div>&nbsp;</div></a>

## New variables resolver
Expand Down
4 changes: 2 additions & 2 deletions lib/plugins/aws/package/compile/events/eventBridge/index.js
Expand Up @@ -13,14 +13,14 @@ class AwsCompileEventBridgeEvents {

this.hooks = {
'initialize': () => {
if (!_.get(this.serverless.service.provider, 'eventBridge.useCloudFormation')) {
if (_.get(this.serverless.service.provider, 'eventBridge.useCloudFormation') == null) {
const hasFunctionsWithEventBridgeTrigger = Object.values(
this.serverless.service.functions
).some(({ events }) => events.some(({ eventBridge }) => eventBridge));
if (hasFunctionsWithEventBridgeTrigger) {
this.serverless._logDeprecation(
'AWS_EVENT_BRIDGE_CUSTOM_RESOURCE',
'AWS EventBridge resources are not being created using native CloudFormation, this is now possible and the use of custom resources is deprecated. Set `eventBridge.useCloudFormation: true` as a provider property to use this now.'
'Starting with "v3.0.0", AWS EventBridge resources will be created using native CloudFormation resources by default. It is possible to use that functionality now by setting "eventBridge.useCloudFormation: true" as provider property in your configuration. If you want to keep using the old creation method, set that property to "false" to hide this deprecation message.'
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/aws/provider.js
Expand Up @@ -851,7 +851,7 @@ class AwsProvider {
eventBridge: {
type: 'object',
properties: {
useCloudFormation: { const: true },
useCloudFormation: { type: 'boolean' },
},
additionalProperties: false,
},
Expand Down
Expand Up @@ -163,8 +163,12 @@ describe('EventBridgeEvents', () => {
const { cfTemplate, awsNaming } = await runServerless({
fixture: 'function',
configExt: {
disabledDeprecations: ['AWS_EVENT_BRIDGE_CUSTOM_RESOURCE'],
...serverlessConfigurationExtension,
provider: {
eventBridge: {
useCloudFormation: false,
},
},
},
command: 'package',
});
Expand Down Expand Up @@ -364,6 +368,21 @@ describe('EventBridgeEvents', () => {
'ERROR_INVALID_REFERENCE_TO_EVENT_BUS_CUSTOM_RESOURCE'
);
});

it('should emit deprecation when `eventBridge.useCloudFormation` is not explicitly set', async () => {
await expect(
runServerless({
fixture: 'function',
configExt: {
...serverlessConfigurationExtension,
},
command: 'package',
})
).to.be.eventually.rejected.and.have.property(
'code',
'REJECTED_DEPRECATION_AWS_EVENT_BRIDGE_CUSTOM_RESOURCE'
);
});
});

describe('using native CloudFormation', () => {
Expand Down

0 comments on commit bf62b7c

Please sign in to comment.