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
Add forceDeploy property in Cognito User Pools #10435
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @TsimpDim, that looks very promising. Have you confirmed locally it does the job?
@@ -171,6 +172,7 @@ class AwsCompileCognitoUserPoolEvents { | |||
} | |||
|
|||
let customCognitoUserPoolResource; | |||
const forceDeployProperty = forceDeploy ? Math.random() * 10 : 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's maybe set it to Date.now()
, and do not set ForceDeploy
(we can assign undefined
) if no forceDeploy
was set
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated!
During deployment the Triggers still get removed for a little while until CF updates all the resources, but they eventually get added back. I'm not sure if we could improve this at all, but either way it is a way better solution then what one has to implement to circumvent this issue currently :D |
}); | ||
|
||
it('should create the necessary resources for the most minimal configuration with forceDeploy', () => { | ||
awsCompileCognitoUserPoolEvents.serverless.service.functions = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, didn't notice that one earlier.
In new tests we always rely on runServerless
util (we have already a tons of tests configured for it, which can self as reference).
Can you update that one, so it's also runServerless
based?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure! I had to do some reading because I'm not familiar at all with testing in Javascript (or the internals of Serverless) but I came up with this:
it('should create the necessary resources for the most minimal configuration with forceDeploy', () =>
runServerless({
fixture: 'cognitoUserPool',
configExt: {
functions: {
existingSimple: {
events: [
{
cognitoUserPool: {
forceDeploy: true
},
},
],
}
}
},
command: 'package',
}).then(({ awsNaming, cfTemplate }) => {
const { Resources } = cfTemplate;
let customResource = Resources[awsNaming.getCustomResourceCognitoUserPoolResourceLogicalId('existingSimple')];
expect(customResource.Properties.ForceDeploy).to.not.deep.equal(undefined);
}));
(only one expect()
statement instead of the previous three, for now at least). Will something like this do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that looks very good.
Just use async/await (instead of .then()
), and rather confirm on property as expect(typeof ..).to.equal('string')
I updated the test: I could not find a better way of specifying what I also updated the documentation to show the new flag. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @TsimpDim I have just two minor suggestions, and otherwise, it looks good to me
test/unit/lib/plugins/aws/package/compile/events/cognitoUserPool.test.js
Outdated
Show resolved
Hide resolved
test/unit/lib/plugins/aws/package/compile/events/cognitoUserPool.test.js
Outdated
Show resolved
Hide resolved
Codecov Report
@@ Coverage Diff @@
## master #10435 +/- ##
=======================================
Coverage 85.43% 85.44%
=======================================
Files 336 336
Lines 14003 14004 +1
=======================================
+ Hits 11964 11966 +2
+ Misses 2039 2038 -1
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @TsimpDim that looks great!
I see that this feature was pushed to version 2.71.0 - can anyone confirm that it works in versions |
It works for me!
|
One followup question, related to @TsimpDim 's comment about how the triggers seem to get removed for a little bit during the deploy, then added back in. If that's the case, it seems like unless you change your Cognito pool frequently, it'd be best to only add the |
I have been struggling with this issue for a very long time, but finally been resolved! THANKS! By adding "forceDeploy: true" it solved the problem. 🍻 |
I tried to implement the proposed solution which can be found here. I added a
forceDeploy
flag that once set will set a random property in the custom resource that is used to attach triggers - if the flag is set to false then it sets the property to0
. I updated tests as well, and made sure the linter is happy.Addresses: #9635