Skip to content

Commit

Permalink
feat(AWS EventBridge): Change default deployment method to native CF
Browse files Browse the repository at this point in the history
BREAKING CHANGE: By default, EventBridge resources now will be deployed using
native CloudFormation resources instead of Custom Resources.
  • Loading branch information
pgrzesik authored and medikoo committed Jan 27, 2022
1 parent 1139255 commit 46956f3
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 42 deletions.
10 changes: 10 additions & 0 deletions docs/deprecations.md
Expand Up @@ -38,6 +38,16 @@ Note:
- The `serverless.yml` setting is ineffective for deprecations reported before the configuration is read.
- `SLS_DEPRECATION_DISABLE` and `disabledDeprecations` remain respected, and no errors will be thrown for mentioned deprecation codes.

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

## AWS EventBridge lambda event triggers based on Custom Resources

Deprecation code: `AWS_EVENT_BRIDGE_CUSTOM_RESOURCE_LEGACY_OPT_IN`

Support for provisioning AWS EventBridge resources without native CloudFormation resources is deprecated and will no longer be maintained. If you want to upgrade to native CloudFormation, remove "eventBridge.useCloudFormation" setting from your configuration. If you are currently using "eventBridge.useCloudFormation" set to `true` to enable native CloudFormation, you can safely remove this setting from your configuration.

Note that to migrate away from the legacy behavior, you will need to remove (or comment) EventBridge triggers, deploy, re-add them and re-deploy in order to migrate from the legacy behavior.

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

## Ineffective property `provider.httpApi.useProviderTags`
Expand Down
38 changes: 30 additions & 8 deletions lib/plugins/aws/package/compile/events/eventBridge/index.js
Expand Up @@ -13,16 +13,38 @@ class AwsCompileEventBridgeEvents {

this.hooks = {
'initialize': () => {
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) {
const useCloudFormation = _.get(
this.serverless.service.provider,
'eventBridge.useCloudFormation'
);
const hasFunctionsWithEventBridgeTrigger = Object.values(
this.serverless.service.functions
).some(({ events }) => events.some(({ eventBridge }) => eventBridge));

if (hasFunctionsWithEventBridgeTrigger) {
if (useCloudFormation === false) {
this.serverless._logDeprecation(
'AWS_EVENT_BRIDGE_CUSTOM_RESOURCE',
'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.'
'AWS_EVENT_BRIDGE_CUSTOM_RESOURCE_LEGACY_OPT_IN',
'Support for provisioning AWS EventBridge resources without native CloudFormation' +
' resources is deprecated and will no longer be maintained. If you want to' +
' upgrade to native CloudFormation, remove "eventBridge.useCloudFormation"' +
' setting from your configuration.'
);
} else if (useCloudFormation === true) {
this.serverless._logDeprecation(
'AWS_EVENT_BRIDGE_CUSTOM_RESOURCE_LEGACY_OPT_IN',
'Provisioning AWS EventBridge resources with native CloudFormation is now' +
' enabled by default. Please remove "eventBridge.useCloudFormation" from your' +
' configuration as this setting will not be recognized in the next major release.'
);
}
} else if (useCloudFormation != null) {
this.serverless._logDeprecation(
'AWS_EVENT_BRIDGE_CUSTOM_RESOURCE_LEGACY_OPT_IN',
'Your service does not configure any "eventBridge" events. Please remove' +
' "eventBridge.useCloudFormation" from your configuration as this setting' +
' will not be recognized in the next major release.'
);
}
},
'package:compileEvents': this.compileEventBridgeEvents.bind(this),
Expand Down Expand Up @@ -114,7 +136,7 @@ class AwsCompileEventBridgeEvents {
const { compiledCloudFormationTemplate } = provider;
const iamRoleStatements = [];
const { eventBridge: options } = provider;
const shouldUseCloudFormation = options ? options.useCloudFormation : false;
const shouldUseCloudFormation = options ? options.useCloudFormation : true;
let hasEventBusesIamRoleStatement = false;
let anyFuncUsesEventBridge = false;

Expand Down
12 changes: 6 additions & 6 deletions test/integration/aws/eventBridge.test.js
Expand Up @@ -50,7 +50,12 @@ describe('AWS - Event Bridge Integration Test', () => {
arnEventBusArn = (await createEventBus(arnEventBusName)).EventBusArn;
// update the YAML file with the arn
await serviceData.updateConfig({
disabledDeprecations: ['AWS_EVENT_BRIDGE_CUSTOM_RESOURCE'],
disabledDeprecations: ['AWS_EVENT_BRIDGE_CUSTOM_RESOURCE_LEGACY_OPT_IN'],
provider: {
eventBridge: {
useCloudFormation: false,
},
},
functions: {
eventBusDefaultArn: {
events: [
Expand Down Expand Up @@ -183,11 +188,6 @@ describe('AWS - Event Bridge Integration Test', () => {
// NOTE: deployment can only be done once the Event Bus is created
arnEventBusArn = (await createEventBus(arnEventBusName)).EventBusArn;
await serviceData.updateConfig({
provider: {
eventBridge: {
useCloudFormation: true,
},
},
functions: {
eventBusDefaultArn: {
events: [
Expand Down
Expand Up @@ -164,6 +164,7 @@ describe('EventBridgeEvents', () => {
fixture: 'function',
configExt: {
...serverlessConfigurationExtension,
disabledDeprecations: ['AWS_EVENT_BRIDGE_CUSTOM_RESOURCE_LEGACY_OPT_IN'],
provider: {
eventBridge: {
useCloudFormation: false,
Expand Down Expand Up @@ -284,7 +285,12 @@ describe('EventBridgeEvents', () => {
runServerless({
fixture: 'function',
configExt: {
disabledDeprecations: ['AWS_EVENT_BRIDGE_CUSTOM_RESOURCE'],
disabledDeprecations: ['AWS_EVENT_BRIDGE_CUSTOM_RESOURCE_LEGACY_OPT_IN'],
provider: {
eventBridge: {
useCloudFormation: false,
},
},
functions: {
basic: {
events: [
Expand Down Expand Up @@ -316,7 +322,12 @@ describe('EventBridgeEvents', () => {
runServerless({
fixture: 'function',
configExt: {
disabledDeprecations: ['AWS_EVENT_BRIDGE_CUSTOM_RESOURCE'],
disabledDeprecations: ['AWS_EVENT_BRIDGE_CUSTOM_RESOURCE_LEGACY_OPT_IN'],
provider: {
eventBridge: {
useCloudFormation: false,
},
},
functions: {
basic: {
events: [
Expand Down Expand Up @@ -347,7 +358,12 @@ describe('EventBridgeEvents', () => {
runServerless({
fixture: 'function',
configExt: {
disabledDeprecations: ['AWS_EVENT_BRIDGE_CUSTOM_RESOURCE'],
disabledDeprecations: ['AWS_EVENT_BRIDGE_CUSTOM_RESOURCE_LEGACY_OPT_IN'],
provider: {
eventBridge: {
useCloudFormation: false,
},
},
functions: {
basic: {
events: [
Expand All @@ -368,21 +384,6 @@ 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 Expand Up @@ -429,11 +430,6 @@ describe('EventBridgeEvents', () => {
const { cfTemplate, awsNaming } = await runServerless({
fixture: 'function',
configExt: {
provider: {
eventBridge: {
useCloudFormation: true,
},
},
functions: {
basic: {
events: [
Expand Down Expand Up @@ -595,11 +591,6 @@ describe('EventBridgeEvents', () => {
fixture: 'function',
command: 'package',
configExt: {
provider: {
eventBridge: {
useCloudFormation: true,
},
},
functions: {
basic: {
events: [
Expand Down Expand Up @@ -677,4 +668,23 @@ describe('EventBridgeEvents', () => {
});
});
});

it('should trigger deprecation when `useCloudFormation` is set without any `eventBridge` events', async () => {
await expect(
runServerless({
fixture: 'function',
command: 'package',
configExt: {
provider: {
eventBridge: {
useCloudFormation: true,
},
},
},
})
).to.be.eventually.rejected.and.have.property(
'code',
'REJECTED_DEPRECATION_AWS_EVENT_BRIDGE_CUSTOM_RESOURCE_LEGACY_OPT_IN'
);
});
});

0 comments on commit 46956f3

Please sign in to comment.