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

chore(aws): remove deprecated support for maximumEventAge & maximumRetryAttempts on destination #8138

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
96 changes: 0 additions & 96 deletions lib/plugins/aws/package/compile/functions/index.test.js
Expand Up @@ -2725,54 +2725,6 @@ describe('AwsCompileFunctions #2', () => {
);
});

it('Should support maximumEventAge defined on destination', () => {
const maximumEventAge = 3600;
return fixtures
.extend('functionDestinations', {
functions: { trigger: { destinations: { maximumEventAge } } },
})
.then(fixturePath =>
runServerless({
cwd: fixturePath,
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 fixtures
.extend('functionDestinations', {
functions: {
trigger: {
maximumEventAge: maximumEventAgeOnFunction,
destinations: { maximumEventAge: maximumEventAgeOnDestination },
},
},
})
.then(fixturePath =>
runServerless({
cwd: fixturePath,
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 fixtures
Expand All @@ -2793,54 +2745,6 @@ describe('AwsCompileFunctions #2', () => {
})
);
});

it('Should support maximumRetryAttempts defined on destination', () => {
const maximumRetryAttempts = 0;
return fixtures
.extend('functionDestinations', {
functions: { trigger: { destinations: { maximumRetryAttempts } } },
})
.then(fixturePath =>
runServerless({
cwd: fixturePath,
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 fixtures
.extend('functionDestinations', {
functions: {
trigger: {
maximumRetryAttempts: maximumRetryAttemptsOnFunction,
destinations: { maximumRetryAttempts: maximumRetryAttemptsOnDestination },
},
},
})
.then(fixturePath =>
runServerless({
cwd: fixturePath,
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