Repository navigation
BREAKING - Refactor function arn generation for info plugin - #3125
Conversation
78ec9f8 to
a6c3240
Compare
|
|
||
| this.serverless.service.getAllFunctions().forEach((func) => { | ||
| const functionInfo = {}; | ||
| const name = `${this.serverless.service.service}-${stage}-${func}`; |
There was a problem hiding this comment.
Is it possible to instead get this out of CloudFormation's ListStackResources API as the PhysicalResourceId? For Lambda functions I'm not sure what CFN uses as a physical ID, but it may be the ARN, which would let us avoid auto-building ARNs here.
There was a problem hiding this comment.
Thanks for pointing into that direction @ryansb ! I'll look into it.
Will be more reliable when fetching through this API
eahefnawy
left a comment
There was a problem hiding this comment.
Thanks for taking a dive into this @pmuens ... However, I feel that the implementation still lacks solutions to the challenges I mentioned earlier, mainly with regard to regions. So the ARNs that are computed are not really accurate.
That makes me doubt the usefulness of this feature in general. I'm starting to think that displaying function ARNs is not really worth the trouble. But I'm open for ideas! 😊
| newOutputObject); | ||
|
|
||
| // Add function versions to Outputs section | ||
| const functionVersionOutputLogicalId = this.provider.naming |
There was a problem hiding this comment.
I am assuming this is only added if users opt-in function versioning. Do you think there's a way to compute function version arns on the fly as well?
There was a problem hiding this comment.
Yes, that's right. The conditional for adding it to the template (or not) is here
| }) | ||
| .then(() => this.provider.getAccountId()) | ||
| .then((accountId) => { | ||
| const stage = this.provider.getStage(); |
There was a problem hiding this comment.
If I understand this correctly, this is based on the region option, along with the us-east-1 default. So the generated ARNs don't reflect what is actually deployed. So if I only deploy to us-west-2 and then run sls info, that would generate ARNs pointing to none existing functions in us-east-1. Is that correct?
There was a problem hiding this comment.
Yes. I'll update the code so that this.options.region is used. This is used anyway for the retrieval. See here:
serverless/lib/plugins/aws/info/getStackInfo.js
Lines 25 to 26 in a6c3240
| this.gatheredData.info.functions = []; | ||
|
|
||
| this.serverless.service.getAllFunctions().forEach((func) => { | ||
| const functionInfo = {}; |
There was a problem hiding this comment.
The same comment above, but for stage as well.
There was a problem hiding this comment.
Also, this should handle the case where a lambda function has a custom name.
There was a problem hiding this comment.
Yep. I agree. But in this case the getAllFunctions() method should handle the correct name retrieval.
There was a problem hiding this comment.
Yep that works too. But maybe that would make the service class AWS specific rather than provider agnostic? I'm sensing that we need a method in the provider class, but not worth it considering the upcoming changes 😉
| return returnValue; | ||
| } | ||
|
|
||
| getAccountId() { |
There was a problem hiding this comment.
Nice!!! ❤️ ... We've needed this for so long already!
|
@ryansb and @eahefnawy thanks for reviewing the PR and proposing changes! I've updated the PR accordingly. The serverless/lib/plugins/aws/info/getStackInfo.js Lines 25 to 26 in a6c3240 I agree that we might drop this function if it needs more attention and gets more complicated to generate the ARNs on the fly. The generation of the ARNs is only used when the |
|
Yep. Exactly @eahefnawy 👍 Thanks for merging! |
|
This change makes it so that we cannot use Serverless. We don't have "iam:GetUser" rights. We don't have users, for that matter. This is not something we can change. We can do |
|
Incidentally, this code is used during |
|
I'll write up a bug |
|
As linked, an issue is opened. I've offered a PR (#3152) containing a potential fix as well. |
|
Oh damn. Sorry for that @erikerikson and thanks for the PR! 👍 Seems like other users are also suffering from that (see: #3140). Will review the PR today! |
What did you implement:
Closes #1825 and refs #2853
The function ARNs are now computed on the fly. Function ARN outputs are no longer generated which reduces the size of CloudFormation Outputs dramatically.
How did you implement it:
Added a
getAccountId()method in the provider plugin. Furthermore the adding of the function output is removed in the compile functions step. The arns will be computed on the fly when invoking theinfocommand.How can we verify it:
Deploy a service and run
serverless info. Furthermore look into the CloudFormation Outputs section in the AWS console.Todos:
Is this ready for review?: YES
Is it a breaking change?: YES