-
Notifications
You must be signed in to change notification settings - Fork 4
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
CMDCT-4184 cdk-side prepping cdk to import Cloudfront Distribution #14991
Open
peoplespete
wants to merge
10
commits into
jon-cdk
Choose a base branch
from
cmdct-4184-cdk
base: jon-cdk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
454c8f6
CMDCT-4184 removing some things to prep for import
peoplespete 1717672
CMDCT-4184 - end state for cloudfront distribution
peoplespete 3794bdf
CMDCT-4184 - adds import instructions for serverless -> cdk cutover
peoplespete 3935ac4
CMDCT-4184 - cleaning up whitespace and comments
peoplespete 1b8b11d
CMDCT-4188 - comments out distribution with dependencies
peoplespete 7777c3a
Revert "CMDCT-4188 - comments out distribution with dependencies"
peoplespete 75311cc
CMDCT-4188 - import instructions now ready for failed conversion to cdk
peoplespete a1ff265
CMDCT-4188 - prepping for a potential need to revert conversion to cd…
peoplespete 6ef6632
CMDCT-4194 - fixes env bug for table names
peoplespete 73b225b
CMDCT-4194 cdk side, creating a better way to import resources from s…
peoplespete File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,62 @@ | ||
#!/usr/bin/env node | ||
import "source-map-support/register"; | ||
import * as cdk from "aws-cdk-lib"; | ||
import { WithoutImportsParentStack } from "./stacks/without_imports/parent"; | ||
import { WithImportsParentStack} from "./stacks/with_imports/parent"; | ||
import { ParentStack } from "./stacks/parent"; | ||
import { determineDeploymentConfig } from "./deployment-config"; | ||
import { getSecret } from "./utils/secrets-manager"; | ||
import { getDeploymentConfigParameters } from "./utils/systems-manager"; | ||
|
||
async function main() { | ||
try { | ||
const app = new cdk.App({ | ||
defaultStackSynthesizer: new cdk.DefaultStackSynthesizer( | ||
JSON.parse((await getSecret("cdkSynthesizerConfig"))!) | ||
), | ||
}); | ||
const app = new cdk.App({ | ||
defaultStackSynthesizer: new cdk.DefaultStackSynthesizer( | ||
JSON.parse((await getSecret("cdkSynthesizerConfig"))!) | ||
), | ||
}); | ||
|
||
const stage = app.node.getContext("stage"); | ||
const config = await determineDeploymentConfig(stage); | ||
const stage = app.node.getContext("stage"); | ||
const config = await determineDeploymentConfig(stage); | ||
|
||
const parametersToFetch = { | ||
cloudfrontCertificateArn: { | ||
name: "cloudfront/certificateArn", | ||
useDefault: true, | ||
}, | ||
cloudfrontDomainName: { | ||
name: "cloudfront/domainName", | ||
useDefault: false, | ||
}, | ||
vpnIpSetArn: { name: "vpnIpSetArn", useDefault: true }, | ||
vpnIpv6SetArn: { name: "vpnIpv6SetArn", useDefault: true }, | ||
hostedZoneId: { name: "route53/hostedZoneId", useDefault: true }, | ||
domainName: { name: "route53/domainName", useDefault: true }, | ||
}; | ||
const parametersToFetch = { | ||
cloudfrontCertificateArn: { | ||
name: "cloudfront/certificateArn", | ||
useDefault: true, | ||
}, | ||
cloudfrontDomainName: { | ||
name: "cloudfront/domainName", | ||
useDefault: false, | ||
}, | ||
vpnIpSetArn: { name: "vpnIpSetArn", useDefault: true }, | ||
vpnIpv6SetArn: { name: "vpnIpv6SetArn", useDefault: true }, | ||
hostedZoneId: { name: "route53/hostedZoneId", useDefault: true }, | ||
domainName: { name: "route53/domainName", useDefault: true }, | ||
}; | ||
|
||
const deploymentConfigParameters = await getDeploymentConfigParameters( | ||
parametersToFetch, | ||
stage | ||
); | ||
const deploymentConfigParameters = await getDeploymentConfigParameters( | ||
parametersToFetch, | ||
stage | ||
); | ||
|
||
cdk.Tags.of(app).add("STAGE", stage); | ||
cdk.Tags.of(app).add("PROJECT", config.project); | ||
cdk.Tags.of(app).add("STAGE", stage); | ||
cdk.Tags.of(app).add("PROJECT", config.project); | ||
|
||
new ParentStack(app, `${config.project}-${stage}`, { | ||
...config, | ||
env: { | ||
account: process.env.CDK_DEFAULT_ACCOUNT, | ||
region: process.env.CDK_DEFAULT_REGION, | ||
}, | ||
deploymentConfigParameters, | ||
}); | ||
} catch (error) { | ||
console.error("Error:", error); | ||
process.exit(1); | ||
let correctParentStack; | ||
if (process.env.WITHOUT_IMPORTS) { | ||
correctParentStack = WithoutImportsParentStack | ||
} else if (process.env.WITH_IMPORTS) { | ||
correctParentStack = WithImportsParentStack | ||
} else { | ||
correctParentStack = ParentStack | ||
} | ||
new correctParentStack(app, `${config.project}-${stage}`, { | ||
...config, | ||
env: { | ||
account: process.env.CDK_DEFAULT_ACCOUNT, | ||
region: process.env.CDK_DEFAULT_REGION, | ||
}, | ||
deploymentConfigParameters, | ||
}); | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
# Import Instructions | ||
|
||
## From `pete-sls` branch: | ||
|
||
1. Deploy sls to get it ready for deletion with retained resources configured for import | ||
|
||
``` | ||
./run deploy --stage <YOUR_BRANCH_NAME> | ||
``` | ||
|
||
2. Collect information about the resources we're going to be importing into the new cdk stack. | ||
``` | ||
cloudfront.Distribution - | ||
cognito.UserPool - | ||
``` | ||
|
||
3. Destroy sls | ||
|
||
``` | ||
./run destroy --stage <YOUR_BRANCH_NAME> | ||
``` | ||
|
||
## From `jon-cdk` branch: | ||
|
||
|
||
1. Create just the new cdk stack without anything inside of it. | ||
|
||
```bash | ||
WITHOUT_IMPORTS=true ./run deploy --stage <YOUR_BRANCH_NAME> | ||
``` | ||
|
||
2. Now import all the serverless ejected resources. | ||
|
||
```bash | ||
WITH_IMPORTS=true PROJECT=seds cdk import --context stage=<YOUR_BRANCH_NAME> --force | ||
``` | ||
As this import occurs you'll have to provide the information you gathered just before destroying the serverless stacks. | ||
|
||
3. Run a deploy on that same imported resource set. | ||
|
||
```bash | ||
WITH_IMPORTS=true ./run deploy --stage <YOUR_BRANCH_NAME> | ||
``` | ||
|
||
4. Run a full deploy by kicking off the full cdk deploy via Github Action. Permissions for individual developers are limited so you must use Github Action to do this part. | ||
|
||
5. Find the Cloudfront Url in the Github Action's logs (or in the outputs section of your Cloudformation Stack). Visit the site and confirm that you can login and use the application. :tada: Congrats, you did it! | ||
|
||
|
||
## What if it all goes pear shaped? | ||
|
||
### If during the middle of the migration, things begin to break and we need to reinstate the serverless stack, we need a way to bring the Cloudfront Distribution back into the newly rebuilt serverless stack. Fortunately this is possible if you follow these steps. | ||
|
||
:grey_exclamation: These instructions are specific to reimporting a Cloudfront Distribution but the same pattern should also apply to any other imported resources that need un-importing should the need arise. | ||
|
||
1) Get the Cloudfront Distribution unaffiliated with any Cloudformation stack. If it's already been successfully imported into the new cdk stack then you'll need to destroy the cdk stack to eject it from that stack. | ||
``` | ||
# this assumes you're on `jon-cdk` branch | ||
./run destroy --stage <YOUR_BRANCH_NAME> | ||
``` | ||
|
||
2) Now you need switch to `pete-sls` branch and comment out any CloudfrontDistribution and dependent configuration. | ||
These are the necessary changes: https://github.com/Enterprise-CMCS/macpro-mdct-seds/commit/8eb551f980a37355729dc1795f5d229987699c84 | ||
|
||
3) Deploy serverless stack (without CloudfrontDistribution) via Github Action (necessary because of permissions limitations) by pushing up changes made in the last step. | ||
|
||
4) Now you need to import the CloudfrontDistribution to the existing ui-XXXXX stack created by the last step. First you'll need to get the existing stack's template and save it to a local file. | ||
``` | ||
aws cloudformation get-template --stack-name ui-cmdct-4188-sls | jq '.TemplateBody' > deployment/cfn_template.json | ||
``` | ||
|
||
5) Now open up the file you just created (deployment/cfn_template.json) and add the following Cloudfront Distribution config to it's resources section: | ||
```json | ||
"CloudFrontDistribution": { | ||
"Type": "AWS::CloudFront::Distribution", | ||
"DeletionPolicy": "Retain", | ||
"Properties": { | ||
"DistributionConfig": { | ||
"CustomOrigin": { | ||
"DNSName": "www.example.com", | ||
"OriginProtocolPolicy": "http-only", | ||
"OriginSSLProtocols": [ | ||
"TLSv1" | ||
] | ||
}, | ||
"Enabled": true, | ||
"DefaultCacheBehavior": { | ||
"CachePolicyId": "Managed-CachingDisabled", | ||
"TargetOriginId": "some_target_origin_id", | ||
"ViewerProtocolPolicy": "allow-all" | ||
} | ||
} | ||
} | ||
}, | ||
``` | ||
|
||
6) Now open up the AWS console and navigate to the Cloudformation console's show page for the particular ui-XXXXX stack. | ||
|
||
7) Import the stack by doing the following: | ||
- Under `Stack Actions` select `Import resources into stack` | ||
- In the `Specify template` section choose upload a template file and upload the one we just created: `deployment/cfn_template.json` | ||
- In the `Identify resources` section you'll have to provide the ID of the incoming Cloudfront Distribution | ||
- Next and confirm until it begins the import | ||
|
||
8) Once the import is complete, take a breath. | ||
|
||
9) Revert the changes where you commented out the Serverless definition of Cloudfront Distribution (undo step 2). | ||
|
||
10) Verify that the Serverless definition now contains the Cloudfront Distribution then deploy via Github Action. | ||
|
||
11) Verify that Cloudfront Distribution is back into the stack and appropriately pointing at the application. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This was never actually being created or used.