aws-cdk icon indicating copy to clipboard operation
aws-cdk copied to clipboard

Reduce number of parameters used by assets

Open alexdilley opened this issue 7 years ago • 75 comments

  • I'm submitting a ...

    • [ ] :beetle: bug report
    • [x] :rocket: feature request
    • [ ] :books: construct library gap
    • [ ] :phone: security issue or vulnerability => Please see policy
    • [ ] :question: support request => Please see note at the top of this template.
  • What is the current behavior?

CloudFormation stacks are limited to 60 parameters; CDK produces a seemingly excessive number of parameters, thus easy to breach limitation.

  • What is the expected behavior (or behavior of feature suggested)?

To perhaps instead use mappings, as suggested in the CF docs.

  • What is the motivation / use case for changing the behavior or adding this feature?

To be able to define, for example, more than 20 Lambda functions in a stack: currently – for each function – CDK generates one parameter for its artifact hash, one for its S3 location, and one for its version.

alexdilley avatar Jul 29 '19 10:07 alexdilley

Hi @alexdilley,

Thank you for reaching out! We are aware of this gap, and will address it when able. Someone will update this issue when that happens.

NGL321 avatar Jul 29 '19 21:07 NGL321

Hi @NGL321,

Thanks for your response.

We, Just started using CDK and ended up with this issue. We have 21 lambdas and the parameter count for it comes to more than 63. This makes it impossible for us to use CDK right now to deploy as cloudformation doesn't allow it. Anyway to make CDK inline the parameters (bucket/key/version hash) within the template directly instead of passing these as parameters ?

niranjan94 avatar Aug 27 '19 07:08 niranjan94

Current workound that I have been using is

  1. synthesizing the template with cdk
  2. then modifying the template to include s3 bucket and uri inline in the template instead of parameters
  3. then using aws cloudformation deploy to deploy instead of cdk deploy

Code snippet incase anyone else needs to use it: https://gist.github.com/niranjan94/92f2636a29f09bd6cc53085951e78046

niranjan94 avatar Aug 27 '19 09:08 niranjan94

The long-term solution should be to have only a single parameter per CDK asset. It will still require a parameter per asset since asset locations change based on their source hash but it will reduce the number of parameters by a factor of x3

eladb avatar Aug 27 '19 09:08 eladb

The long-term solution should be to have only a single parameter per CDK asset. It will still require a parameter per asset since asset locations change based on their source hash but it will reduce the number of parameters by a factor of x3

I do not see why all parameters cannot be placed into a map parameter. They must have unique keys/ids already since parameters cannot have duplicated names, correct?

I do not think the community would consider a stack limited to 30 assets to be the long term solution. 30 assets, assuming the users needed no parameters of their own (a pretty faulty assumption imho).

sublimemm avatar Sep 06 '19 18:09 sublimemm

@sublimemm I think that would also be the best way; however I'm not sure how it could be a map. CloudFormation doesn't seem to support pulling out values from a map unless it's specifically a Mapping. Is there some function I'm missing?

What I've seen is having a long string as the parameter (joining all the parameters with a special character such as |) and then using a combination of !Split and !Select. CDK would have to maintain the appropriate indices for each asset with this solution.

dehli avatar Sep 09 '19 13:09 dehli

@eladb You said the one parameter per asset would reduce the number of parameters by a factor of 3, but I think it will actually do much more. Our stack has 5 assets and between them 63 parameters. So reducing it to 5 would be a much more palatable solution.

It's unclear to me when the CDK decides something is a new asset or not... but I thought your original suggestion was one parameter per construct/lambda/etc. One per asset seems tenable, assuming the cdk is diligent with splitting the stack into assets.

sublimemm avatar Sep 09 '19 13:09 sublimemm

@sublimemm I just looked at my template and it looks like it follows the 3 parameters per asset. Maybe you have something else adding parameters?

dehli avatar Sep 09 '19 13:09 dehli

After some digging, it's all about the lambdas. Its adding 3 per lambda, we have tons of lambdas, there are many per asset.

sublimemm avatar Sep 09 '19 14:09 sublimemm

image

Here are some examples, you can see they're duplicating the bucket (obviously not needed since all CDK stacks are deployed to the same bucket (the toolkit bucket)).

They're also duplicating parameters if multiple lambdas share an asset bundle (we have tons of them that share the same asset path).

sublimemm avatar Sep 09 '19 14:09 sublimemm

We are looking into improving this as part of our work on CI/CD. The current thinking is to actually reduce the number of asset parameters to zero by using a well-known convention-based physical names for the bootstrapping resources (bucket/ECR repository) and the source hash as the key (S3 object key/docker image tag). This will basically mean that we don't need any degrees of freedom during deployment. I am curious about people's thoughts on this...

eladb avatar Sep 09 '19 15:09 eladb

We are looking into improving this as part of our work on CI/CD. The current thinking is to actually reduce the number of asset parameters to zero by using a well-known convention-based physical names for the bootstrapping resources (bucket/ECR repository) and the source hash as the key (S3 object key/docker image tag). This will basically mean that we don't need any degrees of freedom during deployment. I am curious about people's thoughts on this...

I think that is a great solution.

sublimemm avatar Sep 10 '19 12:09 sublimemm

To add to this... I'm hitting my max parameters (60) while using CDK assets for AppSync FunctionConfigs and Resolvers. I have about 33 resolvers and it looks like CDK creates 3 parameters per asset (as mentioned above). Asset parameters to zero would help me a ton!

dsmrt avatar Nov 16 '19 04:11 dsmrt

I'm attempting to migrate from raw CF YAML templates to the CDK, immediately hit this issue. It generated 120 parameters first attempt. Immediately blocked by this. I just spent 3 days converting templates thinking "surely cdk handles maximum limits". Very very discouraging to see this happen before ever being able to deploy our structure. We have 10s of thousands of lines of config and I want to move the team away from that.

Would love to see some progress made toward this fix.

In the meantime, anyone have a workaround aside from the one above? Would re-structuring the hierarchy in some way help? I've tried to create extra layers but they then just pass the parameters through the layer and the problem remains.

tekdroid avatar Nov 21 '19 19:11 tekdroid

@tekdroid yep. I tried restructuring too. But didn't work out. So I'm still using the workaround I told about above. (Inlining all the asset paths into the template) and using aws cloudformation deploy to deploy instead of cdk deploy

Updated script to do the inlining in case you are interested:

https://gist.github.com/niranjan94/92f2636a29f09bd6cc53085951e78046

niranjan94 avatar Nov 22 '19 05:11 niranjan94

@niranjan94 thanks for the updated script, I appreciate that! I'll check it out and see if I can use this method for now. Cheers!

tekdroid avatar Nov 22 '19 16:11 tekdroid

@niranjan94 Your script is not working as expected for me. Would you mind helping me out? It removed all of the parameters, but didn't replace their usages.

Is there another medium by which we could chat for a moment? If you can't that's fine, I can reverse engineer this script.

Mainly I just wanted to see if I'm running the synthesis of the cdk output the same way you are. Looks like you're looking for Resource -> Properties -> Content, but I don't have a node at that path. I have Resource -> Properties -> TemplateURL, which is a join function for the s3 bucket/key parameters that were removed.

EDIT: No worries, after second thought I really don't want to go down this road. I'll continue our teams conversion when this is officially fixed inside the CDK.

tekdroid avatar Nov 22 '19 18:11 tekdroid

@eladb I really like reducing the number to zero and using asset hashes. For the toolkit bucket, I would suggest an Fn::ImportValue instead of convention-based names to prevent name squatting attacks.

hoegertn avatar Dec 18 '19 10:12 hoegertn

We can't use Fn::ImportValue because we need to know before deployment where to upload assets (see the cdk-assets RFC).

Copy @rix0rrr

eladb avatar Dec 18 '19 11:12 eladb

Is there any estimates on when a fix for this could be out? I'm trying to make a decision on whether to go with CDK in my team this year or maybe wait it out a bit more xD

andreascasen avatar Jan 03 '20 08:01 andreascasen