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

[WIP] Migration guide from CDK v1.x to v2.0 #8909

Closed
eladb opened this issue Jul 6, 2020 · 2 comments
Closed

[WIP] Migration guide from CDK v1.x to v2.0 #8909

eladb opened this issue Jul 6, 2020 · 2 comments
Labels
closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. effort/large Large work item – several weeks of effort feature-request A feature should be added or improved. management/tracking Issues that track a subject or multiple issues p2

Comments

@eladb
Copy link
Contributor

eladb commented Jul 6, 2020

Nothing to see here (yet)

This issue has been created as part of devising our plan for CDK v2.0 - it is intended to collect the various migration activities users would need in order to move to the new version.


@eladb eladb added the needs-triage This issue or PR still needs to be triaged. label Jul 6, 2020
@eladb eladb assigned eladb and RomainMuller and unassigned eladb Jul 6, 2020
@SomayaB SomayaB added feature-request A feature should be added or improved. management/tracking Issues that track a subject or multiple issues and removed needs-triage This issue or PR still needs to be triaged. labels Jul 9, 2020
@RomainMuller RomainMuller added effort/large Large work item – several weeks of effort p2 labels Aug 12, 2020
@RomainMuller RomainMuller removed their assignment Jun 21, 2021
@michanto
Copy link

michanto commented Aug 21, 2021

I am using onSynthesize to output multiple templates for a source stack and target stack to perform a stack refactor. See CloudFormationController issue.

Pseudocode:

interface ICfnProducer {
  readonly env: Required<Environment>
  readonly artifactId: string
  readonly artifactFileName: string // Contains the refactor step number as part of the file name
  readonly artifactDirectory: string // Isolate refactor templates in a sub directory of cdk.out.
  _toCloudFormation(): object
}

class CustomSynthesis extends Construct {
  readonly cfnp: ICfnProducer // Passed to constructor
  
  onSynthesize(s: ISynthesisSession) {
     writeJson(`${s.assembly.outdir}/${this.cfnp.artifactDirectory}`,
               `${this.cfnp.artifactFileName}`,
               Stack.of(this).resolve(this.cfnp._toCloudFormation())
     s.assembly.addArtifact(artifactId, {
       type: AWS_CLOUDFORMATION_STACK,
       environment: envUri(this.cfnp.env),
       properties: {
         templateFile: '${this.cfnp.artifactDirectory}/${this.cfnp.artifactFileName}`
       }
  }
}

I use an Aspect to add these CustomSynthesis constructs to the host stack, and everything works great. I get a fully-resolved template in cdk.out, the user uploads the templates to a known S3 location that they can pass to my CustomResource, and my CustomResource can deploy the stack refactor (eventually I would like to use CDK Pipelines to deploy, but that is for another day).

How will I accomplish this without onSynthesize? I see two options, neither of which are very appealing:

  1. Hack the CDK. Copy the ICustomSynthesis symbol and attachCustomSynthesis method. Create my CustomSynthesis construct under the App instead of under the host Stack (giving it a pointer to the stack so it can call resolve), and write away. This is basically what CDK Pipelines does, but they are inside the box, not outside.
  2. Wrap the host stack synthesizer with my own and call my custom synthesis code at the end of IStackSynthesizer.synthesize(). I don't like this option because now I am deciding what IStackSynthesizer class to wrap, rather than just being able to use the one the host Stack provides.

What do you recommend?

My preference would be for ICustomSynthesis to be public. It seems like the easiest choice.

Added here as per these instructions.

@github-actions
Copy link

This issue has not received any attention in 1 year. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Aug 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. effort/large Large work item – several weeks of effort feature-request A feature should be added or improved. management/tracking Issues that track a subject or multiple issues p2
Projects
None yet
Development

No branches or pull requests

4 participants