We use machine learning technology to do auto-translation. Click "English" on top navigation bar to check Chinese version.
NetDevSecOps to modernize Amazon Web Services networking deployments
NetDevOps orchestrates and automates network changes to shorten the network delivery lifecycle, treats the network as code to allow for version control, and tests changes to make sure of quality and stability. This increased speed helps organizations better serve their customers and compete more effectively in the market. The post
Considerations
Every organization is unique, and there is no single correct approach to implementing NetDevOps. The following section lists some considerations that you must keep in mind during your decision making. These considerations will help you define a framework for releasing changes with confidence, or rollback without causing disruptions.
1/ Infrastructure as Code (IaC) options – Amazon Web Services offers several
Am I working on a simple, mostly serverless solution with minimal dependency or dependents? |
CloudFormation (particularly
|
Do I have a team with a strong programming background ? Do they want to build infrastructure using code? |
Amazon Web Services CDK or Terraform |
Do I want to stay entirely within the Amazon Web Services ecosystem? |
CloudFormation or Amazon Web Services CDK |
Do I need to orchestrate resources outside the Amazon Web Services ecosystem? |
Terraform or Amazon Web Services CDK for Terraform (CDKTF) |
Do I want a cloud agnostic utility , especially for multi/hybrid cloud knowledge transfer? |
Terraform |
2/ Deployment strategies – Define how you want to deploy your network stack. Organizations follow different
3/ Define unit tests – When an organization uses pipelines to provision application and infrastructure, infrastructure testing plays a key role in mitigating problems related to any misconfiguration. The infrastructure team is aware of the organization’s policies. Therefore, it’s essential to write and integrate unit tests as part of the provisioning pipeline. Based on the IaC option you choose, you will create unit test policy tools and unit tests.
4/ Security and compliance tools integration – NetSecOps introduces security to the
5/ Defining stages – You must define the CI/CD of your network as a pipeline, where new network configurations or required changes are submitted as code on one end, pass over a series of stages such as build, test, staging, and validation, before they are deployed in production. Every stage acts like a gatekeeper, assessing a specific part of the code. As the code progresses through the network pipeline, we assume that code in latter stages is higher quality, because it has been verified more times. Problems uncovered in an early stage stop the code from progressing through the pipeline. The network operations team immediately receives the results from the tests, and they stop all further builds and releases if the software doesn’t pass the stage.
6/ Multi-account support – As you adopt Amazon Web Services, you must determine how to meet your business, governance, security, and operational requirements. The use of
7/ Multi-Region support – As part of the organization’s
8/ Monitoring network CI/CD pipelines – You must integrate monitoring that notifies the network operations team on a failure or a specific event.
A practical example
Let’s consider a multi-account, multi-Region scenario where a business wants to centralize all ingress traffic to Amazon Web Services. As part of compliance requirements (
Figure 1: A multi-account hub and spoke design leveraging Transit Gateway
To implement this use case, we take the considerations we highlighted earlier into account when defining our NetDevSecOps Pipeline as shown in figure 2. The results are:
- Consideration 1 (IaC) – We built our infrastructure using the Amazon Web Services CDK, which is synthesized and deployed as part the stages in the deployment.
- Consideration 2 (Deployment strategies) – Under the hood, the Amazon Web Services CDK pipeline construct uses
Amazon Web Services CodePipeline andAmazon Web Services CodeBuild , which is used as part ofcontinuous delivery strategy . Here,we test our infrastructure code and deploy it to our Test and Production environments at different stages in the process. - Consideration 3 (Unit test) – We wrote a pytest to validate the resource property “
Amazon Web Services::CodePipeline::Pipeline ” of the Amazon Web Services CDK Synthesized template. This only deploys resources to the Primary and Disaster Recovery Regions. - Consideration 4 (Security and compliance tools integration) – This compliance check validates that the Hub VPC subnet launched with a Public IP through cfn-nag, and publishes the findings to Security Hub.
- Consideration 5 (Defining stages) – The pipeline has Hub, Spoke, and Validate stages to provision the resources in the Hub and spoke environment. We use
Amazon Web Services VPC Reachability Analyzer to validate connectivity. - Consideration 6 (Multi-account support) – The pipeline provisions resources to the Development and Production environment.
- Consideration 7 (Multi-Region support) – We provision resources in both the Primary and Disaster Recovery Regions.
- Consideration 8 (Monitoring) – We send compliance findings to Security Hub.

Figure 2: NetDevSecOps Pipeline in action
Prerequisites
You need the following:
1. Five
- Development Account – Used to provision the NetDevOps Pipeline (This can also be a shared services or deployment account)
- Dev Hub Account – NetDevOps Pipeline provisions the Dev Hub Workload
- Dev Spoke Account – NetDevOps Pipeline provisions the Dev Spoke Workload
- Prod Hub Account – NetDevOps Pipeline provisions the Prod Hub Workload
- Prod Spoke Account – NetDevOps Pipeline provisions the Prod Spoke Workload
2. Turn on trusted access for
3. Turn on the Delegated administrator account for
4. Configure the Amazon Web Services credentials of the Development account in the terminal.
You must comply with Amazon Web Services standards for inclusive language. Rules on inclusive content, including offensive and sensitive terms, are documented in the Amazon Web Services Style Guide. The Inclusive Terminology Bar page is another useful reference.
Deployment steps
Next, we deploy the code in this
1. NetDevOps foundations application – This Amazon Web Services CDK application provisions all foundations that are required as part of the NetDevOps Pipeline. This includes
2. NetDevOps Pipeline application – This Amazon Web Services CDK application provisions the NetDevOps Pipeline for network infrastructure, with all aforementioned stages in a multi-account and multi-Region setup.
NetDevOps foundations application
1. Clone the repository and bootstrap the application in your local machine by running the following
git clone <repo url> NetDevopsPipeline cd NetDevopsPipeline
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
2. Update accounts.py in the “netdevopspipeline” folder with development, hub, and spoke accounts in the development and production environment as shown in figure 3.

Figure 3: An example accounts.py file
3. Update cdk.json with your email to receive the SNS notification, Organizations ID, and then deploy the NetDevops Foundations Application.
cdk bootstrap aws://<Development account id>/<Primary Region>
cdk deploy -c infra_type=NetDevopsFoundation --require-approval=never
Note : Subscribe the SNS notification sent to the email address mentioned in cdk.json file.
NetDevOps Pipeline application
1. Clone the CodeCommit repository (network-devops-repo) created in the previous step.
git remote add codecommit https://git-codecommit.<Primary Region>.amazonaws.com/v1/repos/network-devops-repo
NOTE: The above step requires setting up Https git credentials. Review the steps to setup git credentials. Due to operational reason if you’re unable to setup git credentials then follow the steps mentioned for git-remote-codecommit setup.
2. Add the code to the repository by running the following commands:
git add .
git commit -m "Initial NetDevops pipeline repo commit"
git push --set-upstream codecommit main
3. Bootstrap the hub account and spoke account in the development and production environment by following these steps. Or, bootstrap the accounts using StackSet, following the steps highlighted in this
Make sure that the correct IAM account credentials are setup during the
Hub Account (Development Environment)
cdk bootstrap aws://<Hub account id>/<Primary Region> —trust <Development account> --cloudformation-execution-policies arn:aws:iam::aws:policy/AdministratorAccess
cdk bootstrap aws://<Hub account id>/<DR Region> —trust <Development account> --cloudformation-execution-policies arn:aws:iam::aws:policy/AdministratorAccess
Spoke Account (Development Environment)
cdk bootstrap aws://<Spoke account id>/<Primary Region> —trust <Development account> --cloudformation-execution-policies arn:aws:iam::aws:policy/AdministratorAccess
cdk bootstrap aws://<Spoke account id>/<DR Region> --trust <Development account> —cloudformation-execution-policies arn:aws:iam::aws:policy/AdministratorAccess
Hub Account (Production Environment)
cdk bootstrap aws://<Hub account id>/<Primary Region> —trust <Development account> --cloudformation-execution-policies arn:aws:iam::aws:policy/AdministratorAccess
cdk bootstrap aws://<Hub account id>/<DR Region> —trust <Development account> --cloudformation-execution-policies arn:aws:iam::aws:policy/AdministratorAccess
Spoke Account (Production Environment)
cdk bootstrap aws://<Spoke account id>/<Primary Region> —trust <Development account> --cloudformation-execution-policies arn:aws:iam::aws:policy/AdministratorAccess
cdk bootstrap aws://<Spoke account id>/<DR Region> --trust <Development account> —cloudformation-execution-policies arn:aws:iam::aws:policy/AdministratorAccess
4. To provision the NetDevOps Pipeline in the “Development account”, setup the IAM credentials of the pipeline and run the following command. The deployment of NetDevOps Pipeline with all stages is shown in figure 4.
cdk deploy --all --require-approval=never

Figure 4: An example NetDevSecOps pipeline with stages
Note that deployment takes 10-15 minutes because of the CodePipelines and CloudFormation template creation. Check the progress on the
5. The NetDevOps Pipeline has a manual approval stage to validate the hub and spoke connectivity. An Amazon SNS notification is sent when

Figure 5: An example analysis from VPC reachability analyzer
Now you’ve successfully implemented a multi-account, multi-Region NetDevOps Pipeline with the ability to identify one
Validating security and compliance checks
In this step, we validate security and compliance leveraging cfn-nag as part of the pipeline. This is done as part of the build stage (synth-and-deployment-validation):
1. Copy this snippet of code and replace the content of self.vpc present in the DevSpokeInfraStack.py file in the pipeline stack folder as shown in figure 6.
self.vpc = ec2.Vpc(
self,
"spoke_vpc",
max_azs=2,
cidr=cidr,
enable_dns_hostnames=True,
enable_dns_support=True,
subnet_configuration=[
ec2.SubnetConfiguration(
subnet_type=ec2.SubnetType.PRIVATE_ISOLATED,
name="private",
cidr_mask=24,
),
ec2.SubnetConfiguration(
subnet_type=ec2.SubnetType.PRIVATE_ISOLATED,
name="tgw",
cidr_mask=28,
),
ec2.SubnetConfiguration(
subnet_type=ec2.SubnetType.PUBLIC,
name="Public",
cidr_mask=24,
map_public_ip_on_launch=True
)
],
nat_gateways=0,
)

Figure 6 : An example comparison for snippet of code for VPC subnet configuration
2. Push the code changes by running:
git commit -a -m "Adding Public subnet in the spoke stack"
git push codecommit main
Once you push the changes, the pipeline gets invoked and goes to a failed state, and findings are sent to the Security Hub as shown in figure 7.

Figure 7: Findings sent to Amazon Web Services Security Hub
Validating unit tests
The existing NetDevOps Pipeline only allows you to create resources in us-east-1 (Primary Region) and us-west-2 (Secondary Region). If the provisioning occurs in any other Region, then the pipeline fails at the build stage (synth-and-deployment-validation).
1. Update the accounts.py present in the NetDevOps Pipeline folder to provision in any Region other than us-east-1 (Primary Region) and us-west-2 (Secondary Region) as shown in figure 8.

Figure 8: An example of updated accounts.py file
Note that you must make sure the Hub and Spoke accounts are bootstrapped in both the development and production environments in the “us-east-2” Region.
2. Push the code changes by running the following commands:
git commit -a -m "Adding invalid region subnet in the accounts.py"
git push codecommit main
Once the changes are pushed, the pipeline gets invoked, and the pipeline changes to the failed state at the build stage. When reviewing the build failure logs, you can notice it’s due to pytest failed validation as shown in figure 9.

Figure 9: An example pytest failure
Cleanup
To avoid unnecessary charges, delete the resources created during the deployment of NetDevOps Pipeline and testing. To cleanup the resources, perform the following steps in the order shown here:
1. The stacks created by the CodePipeline should be deleted manually from the CloudFormation console. Therefore, identify the stacks, and delete them in hub and spoke accounts in both the primary and DR Regions for the production and development environments. Also, delete the S3 buckets.
2. Destroy the NetDevOps Foundations and NetDevOps Pipeline Applications by running the following commands:
cdk destroy --all
cdk destroy -c infra_type=NetDevopsFoundation
Conclusion
NetDevOps helps you deliver applications and services faster. This means faster changes, and a shorter network delivery lifecycle. In this post, we showed how to implement NetDevSecOps in practice by leveraging Amazon Web Services CDK. We showed how to include security and compliance checks as part of your network CI/CD. We removed the undifferentiated heavy lifting for setting up the CI/CD pipeline by using the provided templates to provision the required infrastructure. We hope that you’ve found this post informative and we look forward to hearing how you use this approach!
About the Authors
The mentioned AWS GenAI Services service names relating to generative AI are only available or previewed in the Global Regions. Amazon Web Services China promotes AWS GenAI Services relating to generative AI solely for China-to-global business purposes and/or advanced technology introduction.