Skip to content

New serverless pattern - cdk-codepipeline-cross-account-deployment #1586

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

Closed

Conversation

c-currie
Copy link

Issue #, if available:

Description of changes:
Created a new serverless pattern example that uses a CodePipeline in one account to deploy an example stack (S3 + CloudFront static site) to multiple accounts.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@c-currie
Copy link
Author

I realized I am missing the pattern.json file, committing again shortly


## Requirements

* [Create AWS account(s)](https://portal.aws.amazon.com/gp/aws/developer/registration/index.html) if you do not already have one and log in. The IAM user that you use must have sufficient permissions to make necessary AWS service calls and manage AWS resources.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do they need to have special permissions to do the cross account? if so please specify

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No additional permissions are required outside of the general requirements required for bootstrapping an environment. I added more info on the next commit about this.


## How It Works

After cloning this pattern, you will bootstrap 2 AWS environments with CDK. An environment is an Account-Region pair. This example uses 2 different accounts as a way to demonstrate deploying the same CDK stack(s) across accounts i.e. Development and Production. The pipeline will only deploy in the account you designate in the app.py file.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are many place where the accounts need to be defined. A better practice is to create a config file where the 2 accounts/regions are specified and then they are called from where you want to deploy. You can create a config_sample.json and upload that to github so you don't make your real config file public.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do agree that providing additional configuration, such as context in the cdk.json file to differentiate between the environments would normally be useful and cleaner, but in this case, we are only deploying 1 time from local, into the primary (environment with pipeline). After this, all deployments can be done through the pipeline through the CI/CD process. Therefore, the additional configuration wouldn't be needed, especially since we are only deploying to the one account locally the one time. Once the pipeline is initialized, the example static site will be deployed to the secondary account from the pipeline.

I added more info about this in the next commit.

```
## Testing

1. After deploying, you can make changes in the repo, and push those changes to main. After these changes are pushed, navigate to the CodePipline dashboard and select the pipline to watch the CI/CD process.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the CodeCommit repo

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the pipeline wont deploy anything when you do the Cdk deploy of your stack locally? If that is the case please specify that, if not please add the testing steps so when you deploy with CDK you can see the 2 stacks in the 2 accounts, and then the step that you can make changes.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More info about this info next commit


1. After deploying, you can make changes in the repo, and push those changes to main. After these changes are pushed, navigate to the CodePipline dashboard and select the pipline to watch the CI/CD process.

2. After the pipline is complete, you can navigate to CloudFront in both accounts and see the distribution that has been created. The CloudFront dashboard will provide you with a URL you can use to navigate to the exmaple website that has been created.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pipeline

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

## Cleanup

1. Delete the stack in both accounts

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and what about the pipeline?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed with more info on next commit

@mavi888
Copy link
Contributor

mavi888 commented Aug 28, 2023

Added some comments to the PR. Please review and fix and I will check it again next week.

@mavi888
Copy link
Contributor

mavi888 commented Sep 18, 2023

This pattern will be closed next week if there are no updates in this PR.
If closed, reopen it again later on with the fixes applied.

Thanks,
Marcia

@c-currie
Copy link
Author

Sorry for delays, fixed all typos and added more information to readme. Thank you!

@mavi888
Copy link
Contributor

mavi888 commented Oct 9, 2023

I'm following the instructions here and i get an error in the cdk synth

cdk synth
Traceback (most recent call last):
  File "/serverless-patterns/cdk-codepipeline-cross-account-deployment/app.py", line 6, in <module>
    from aws_serverless_pattern_cdk_crossaccount_deployment.aws_serverless_pattern_cdk_crossaccount_deployment_stack import AwsServerlessPatternCdkCrossaccountDeploymentStack
  File "/serverless-patterns/cdk-codepipeline-cross-account-deployment/aws_serverless_pattern_cdk_crossaccount_deployment/aws_serverless_pattern_cdk_crossaccount_deployment_stack.py", line 7, in <module>
    from aws_serverless_pattern_cdk_crossaccount_deployment.static_site import WebsiteStage
ImportError: cannot import name 'WebsiteStage' from 'aws_serverless_pattern_cdk_crossaccount_deployment.static_site' (unknown location)

Also nowehere in the readme it says how to configure the 2 accounts in the aws_serverless_pattern_cdk_crossaccount_deployment_stack file and in app.py is not clearly in the deployment instructions.

@c-currie
Copy link
Author

Updated with changes

@mavi888
Copy link
Contributor

mavi888 commented Oct 23, 2023

Hello, im following the instructions but i get an error:

(.venv) ➜  cdk-codepipeline-cross-account-deployment git:(cdk-codepipeline-cross-account) ✗ cdk synth                                 
Traceback (most recent call last):
  File "/Users/lmv/Workdocs/coding-projects/serverless-patterns/cdk-codepipeline-cross-account-deployment/app.py", line 6, in <module>
    from aws_serverless_pattern_cdk_crossaccount_deployment.aws_serverless_pattern_cdk_crossaccount_deployment_stack import AwsServerlessPatternCdkCrossaccountDeploymentStack
  File "/serverless-patterns/cdk-codepipeline-cross-account-deployment/aws_serverless_pattern_cdk_crossaccount_deployment/aws_serverless_pattern_cdk_crossaccount_deployment_stack.py", line 7, in <module>
    from aws_serverless_pattern_cdk_crossaccount_deployment.static_site.website_stage import WebsiteStage
  File "/serverless-patterns/cdk-codepipeline-cross-account-deployment/aws_serverless_pattern_cdk_crossaccount_deployment/static_site/website_stage.py", line 3, in <module>
    from aws_serverless_pattern_cdk_crossaccount_deployment.static_site import DemoWebsiteStack
ImportError: cannot import name 'DemoWebsiteStack' from 'aws_serverless_pattern_cdk_crossaccount_deployment.static_site' (unknown location)

Please fix this before it can be merged

@jbesw
Copy link
Contributor

jbesw commented Oct 27, 2023

This pattern has taken too much time/resources to process. Please focus on simpler patterns or submit as a repo instead.

@jbesw jbesw closed this Oct 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants