mirror of
https://github.com/serverless/serverless.git
synced 2026-01-25 15:07:39 +00:00
Merge pull request #6652 from serverless/fix-cloudfront-removal-logging
Use hooks to log Lambda@Edge removal reminder
This commit is contained in:
commit
c0ec32b4e0
@ -14,27 +14,27 @@ class AwsCompileCloudFrontEvents {
|
||||
'package:initialize': this.validate.bind(this),
|
||||
'before:package:compileFunctions': this.prepareFunctions.bind(this),
|
||||
'package:compileEvents': this.compileCloudFrontEvents.bind(this),
|
||||
'before:remove:remove': this.logRemoveReminder.bind(this),
|
||||
};
|
||||
if (this.serverless.processedInput.commands[0] === 'remove') {
|
||||
this.logRemoveReminder.call(this);
|
||||
}
|
||||
}
|
||||
|
||||
logRemoveReminder() {
|
||||
let isEventUsed = false;
|
||||
const funcKeys = this.serverless.service.getAllFunctions();
|
||||
if (funcKeys.length) {
|
||||
isEventUsed = funcKeys.some(funcKey => {
|
||||
const func = this.serverless.service.getFunction(funcKey);
|
||||
return func.events && func.events.find(e => Object.keys(e)[0] === 'cloudFront');
|
||||
});
|
||||
}
|
||||
if (isEventUsed) {
|
||||
const message = [
|
||||
"Don't forget to manually remove your Lambda@Edge functions ",
|
||||
'once the CloudFront distribution removal is successfully propagated!',
|
||||
].join('');
|
||||
this.serverless.cli.log(message, 'Serverless', { color: 'orange' });
|
||||
if (this.serverless.processedInput.commands[0] === 'remove') {
|
||||
let isEventUsed = false;
|
||||
const funcKeys = this.serverless.service.getAllFunctions();
|
||||
if (funcKeys.length) {
|
||||
isEventUsed = funcKeys.some(funcKey => {
|
||||
const func = this.serverless.service.getFunction(funcKey);
|
||||
return func.events && func.events.find(e => Object.keys(e)[0] === 'cloudFront');
|
||||
});
|
||||
}
|
||||
if (isEventUsed) {
|
||||
const message = [
|
||||
"Don't forget to manually remove your Lambda@Edge functions ",
|
||||
'once the CloudFront distribution removal is successfully propagated!',
|
||||
].join('');
|
||||
this.serverless.cli.log(message, 'Serverless', { color: 'orange' });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -82,15 +82,15 @@ describe('AwsCompileCloudFrontEvents', () => {
|
||||
it('should set the provider variable to an instance of AwsProvider', () =>
|
||||
expect(awsCompileCloudFrontEvents.provider).to.be.instanceof(AwsProvider));
|
||||
|
||||
it('should log an info message if the users wants to remove the stack with a cloudFront event', () => {
|
||||
it('should use "before:remove:remove" hook to log a message before removing the service', () => {
|
||||
serverless.processedInput.commands = ['remove'];
|
||||
serverless.service.functions = {
|
||||
first: {
|
||||
events: [
|
||||
{
|
||||
cloudFront: {
|
||||
eventType: 'viewer-response',
|
||||
origin: 's3://some-bucket.s3.amazonaws.com/files',
|
||||
eventType: 'viewer-request',
|
||||
origin: 's3://bucketname.s3.amazonaws.com/files',
|
||||
},
|
||||
},
|
||||
],
|
||||
@ -98,6 +98,7 @@ describe('AwsCompileCloudFrontEvents', () => {
|
||||
};
|
||||
const awsCompileCloudFrontEventsRemoval = new AwsCompileCloudFrontEvents(serverless, options);
|
||||
|
||||
awsCompileCloudFrontEventsRemoval.hooks['before:remove:remove']();
|
||||
expect(awsCompileCloudFrontEventsRemoval.serverless.cli.log).to.have.been.calledOnce;
|
||||
expect(awsCompileCloudFrontEventsRemoval.serverless.cli.log.args[0][0]).to.include(
|
||||
'remove your Lambda@Edge functions'
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user