Skip to content

Commit

Permalink
refactor(AWS Lambda): Remove support for async config on destination
Browse files Browse the repository at this point in the history
(PR #8138)

BREAKING CHANGE
Support for `maximumEventAge` and `maximumRetryAttemps` as set on `functions[].destinations` was removed.
Those properties should be defined directly on `functions[]`
  • Loading branch information
pgrzesik authored and medikoo committed Sep 10, 2020
1 parent f9c3077 commit e131f26
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 116 deletions.
37 changes: 5 additions & 32 deletions lib/plugins/aws/package/compile/functions/index.js
Expand Up @@ -581,40 +581,19 @@ class AwsCompileFunctions {

compileFunctionEventInvokeConfig(functionName) {
const functionObject = this.serverless.service.getFunction(functionName);
const {
destinations,
maximumEventAge: maximumEventAgeOnFunction,
maximumRetryAttempts: maximumRetryAttemptsOnFunction,
} = functionObject;
let maximumEventAgeOnDestinations;
let maximumRetryAttemptsOnDestinations;

if (!destinations && !maximumEventAgeOnFunction && maximumRetryAttemptsOnFunction == null) {
const { destinations, maximumEventAge, maximumRetryAttempts } = functionObject;

if (!destinations && !maximumEventAge && maximumRetryAttempts == null) {
return;
}

const destinationConfig = {};

if (destinations) {
if (destinations.maximumRetryAttempts != null) {
this.serverless._logDeprecation(
'AWS_FUNCTION_DESTINATIONS_ASYNC_CONFIG',
'destinations.maximumRetryAttempts is deprecated, use maximumRetryAttempts on function instead'
);
maximumRetryAttemptsOnDestinations = destinations.maximumRetryAttempts;
}

if (destinations.maximumEventAge) {
this.serverless._logDeprecation(
'AWS_FUNCTION_DESTINATIONS_ASYNC_CONFIG',
'destinations.maximumEventAge is deprecated, use maximumEventAge on function instead'
);
maximumEventAgeOnDestinations = destinations.maximumEventAge;
}

const hasAccessPoliciesHandledExternally = Boolean(
functionObject.role || this.serverless.service.provider.role
);

if (destinations.onSuccess) {
if (!hasAccessPoliciesHandledExternally) {
this.ensureTargetExecutionPermission(destinations.onSuccess);
Expand All @@ -625,6 +604,7 @@ class AwsCompileFunctions {
: this.provider.resolveFunctionArn(destinations.onSuccess),
};
}

if (destinations.onFailure) {
if (!hasAccessPoliciesHandledExternally) {
this.ensureTargetExecutionPermission(destinations.onFailure);
Expand All @@ -640,13 +620,6 @@ class AwsCompileFunctions {
const cfResources = this.serverless.service.provider.compiledCloudFormationTemplate.Resources;
const functionLogicalId = this.provider.naming.getLambdaLogicalId(functionName);

const maximumEventAge = maximumEventAgeOnFunction || maximumEventAgeOnDestinations;
// For maximumRetryAttempts we cannot rely on "||" as the value can be Falsy, 0
const maximumRetryAttempts =
maximumRetryAttemptsOnFunction == null
? maximumRetryAttemptsOnDestinations
: maximumRetryAttemptsOnFunction;

const resource = {
Type: 'AWS::Lambda::EventInvokeConfig',
Properties: {
Expand Down
84 changes: 0 additions & 84 deletions lib/plugins/aws/package/compile/functions/index.test.js
Expand Up @@ -2708,48 +2708,6 @@ describe('AwsCompileFunctions #2', () => {
});
});

it('Should support maximumEventAge defined on destination', () => {
const maximumEventAge = 3600;
return runServerless({
fixture: 'functionDestinations',
configExt: {
functions: { trigger: { destinations: { maximumEventAge } } },
},
cliArgs: ['package'],
}).then(({ awsNaming, cfTemplate }) => {
const cfResources = cfTemplate.Resources;
const naming = awsNaming;
const eventInvokeConfig =
cfResources[naming.getLambdaEventConfigLogicalId('trigger')].Properties;

expect(eventInvokeConfig.MaximumEventAgeInSeconds).to.equal(maximumEventAge);
});
});

it('Should prefer maximumEventAge defined on function over defined on destination', () => {
const maximumEventAgeOnFunction = 3600;
const maximumEventAgeOnDestination = 7200;
return runServerless({
fixture: 'functionDestinations',
configExt: {
functions: {
trigger: {
maximumEventAge: maximumEventAgeOnFunction,
destinations: { maximumEventAge: maximumEventAgeOnDestination },
},
},
},
cliArgs: ['package'],
}).then(({ awsNaming, cfTemplate }) => {
const cfResources = cfTemplate.Resources;
const naming = awsNaming;
const eventInvokeConfig =
cfResources[naming.getLambdaEventConfigLogicalId('trigger')].Properties;

expect(eventInvokeConfig.MaximumEventAgeInSeconds).to.equal(maximumEventAgeOnFunction);
});
});

it('Should support maximumRetryAttempts defined on function', () => {
const maximumRetryAttempts = 0;
return runServerless({
Expand All @@ -2767,48 +2725,6 @@ describe('AwsCompileFunctions #2', () => {
expect(eventInvokeConfig.MaximumRetryAttempts).to.equal(maximumRetryAttempts);
});
});

it('Should support maximumRetryAttempts defined on destination', () => {
const maximumRetryAttempts = 0;
return runServerless({
fixture: 'functionDestinations',
configExt: {
functions: { trigger: { destinations: { maximumRetryAttempts } } },
},
cliArgs: ['package'],
}).then(({ awsNaming, cfTemplate }) => {
const cfResources = cfTemplate.Resources;
const naming = awsNaming;
const eventInvokeConfig =
cfResources[naming.getLambdaEventConfigLogicalId('trigger')].Properties;

expect(eventInvokeConfig.MaximumRetryAttempts).to.equal(maximumRetryAttempts);
});
});

it('Should prefer maximumRetryAttempts defined on function over on destination', () => {
const maximumRetryAttemptsOnFunction = 0;
const maximumRetryAttemptsOnDestination = 1;
return runServerless({
fixture: 'functionDestinations',
configExt: {
functions: {
trigger: {
maximumRetryAttempts: maximumRetryAttemptsOnFunction,
destinations: { maximumRetryAttempts: maximumRetryAttemptsOnDestination },
},
},
},
cliArgs: ['package'],
}).then(({ awsNaming, cfTemplate }) => {
const cfResources = cfTemplate.Resources;
const naming = awsNaming;
const eventInvokeConfig =
cfResources[naming.getLambdaEventConfigLogicalId('trigger')].Properties;

expect(eventInvokeConfig.MaximumRetryAttempts).to.equal(maximumRetryAttemptsOnFunction);
});
});
});

describe('when using fileSystemConfig', () => {
Expand Down

0 comments on commit e131f26

Please sign in to comment.