Create dynamic CI pipelines for Java and Python projects automatically
Aromal Raj Jayarajan, Vijesh Vijayakumaran Nair, MAHESH RAGHUNANDANAN, and Amarnath Reddy, Amazon Web Services
Summary
This pattern shows how to create dynamic continuous integration (CI) pipelines for Java and Python projects automatically by using AWS developer tools.
As technology stacks diversify and development activities increase, it can become difficult to create and maintain CI pipelines that are consistent across an organization. By automating the process in AWS Step Functions
To automate the creation of dynamic CI pipelines, this pattern uses the following variable inputs:
Programming language (Java or Python only)
Pipeline name
Required pipeline stages
Step Functions orchestrates pipeline creation by using multiple AWS services. For more information about the AWS services used in this solution, see the Tools section of this pattern.
Prerequisites and limitations
Prerequisites
An active AWS account
An Amazon Simple Storage Service (Amazon S3)
bucket in the same AWS Region where you deploy this solution, with public access blocked An AWS Identity and Access Management (IAM)
principal that has the AWS CloudFormation permissions required to create the resources needed for this solution, including IAM roles, a customer managed AWS Key Management Service (AWS KMS) key, and the Step Functions state machine Access to AWS CodeCommit in your AWS account
Limitations
This pattern supports Java and Python projects only. The generated pipelines build and test the sample projects with Java 17 (Amazon Corretto) and Python 3.12.
The IAM roles provisioned in this pattern are designed to follow the principle of least privilege for the CI pipelines that the solution creates. Update the roles’ permissions based on the specific resources that your CI pipeline needs to create.
Deploy one copy of the solution in each AWS account and Region. The IAM roles and policies that the solution creates have fixed names, and the state machine’s permissions are limited to those names.
The generated pipelines run only the CI stages that you select. They don’t deploy anything.
Architecture
Target technology stack
AWS CloudFormation
AWS CodeBuild
AWS CodeCommit
AWS CodePipeline
AWS IAM
AWS Key Management Service (AWS KMS)
Amazon Simple Storage Service (Amazon S3)
AWS Systems Manager
AWS Step Functions
AWS Lambda
Amazon DynamoDB
Amazon CloudWatch Logs
Target architecture
The following diagram shows an example workflow for creating dynamic CI pipelines for Java and Python projects automatically by using AWS developer tools.

The diagram shows the following workflow:
An AWS user provides the input parameters for CI pipeline creation in JSON format. This input starts a Step Functions workflow (state machine) that creates a CI pipeline by using AWS developer tools.
A Lambda function validates the input, reads a folder named input-references from an Amazon S3 bucket, and generates a buildspec.yml file that defines the CI pipeline stages. The function stores the buildspec.yml file and a zip file in the generated-artifacts folder of the same Amazon S3 bucket. The zip file contains the sample source code and the buildspec.yml file.
Step Functions checks the CI pipeline creation workflow’s dependencies for any changes, and updates the dependencies stack as needed.
Step Functions creates the CI pipeline resources in a CloudFormation stack, including a CodeCommit repository, CodeBuild project, and a CodePipeline pipeline.
The CloudFormation stack creates a CodeCommit repository from the zip file, which contains the sample source code for the selected technology stack (Java or Python) and the buildspec.yml file.
An Amazon DynamoDB table, encrypted with an AWS KMS customer managed key, stores CI pipeline runtime details and the status of each request. If an input isn’t valid or a stack fails, the workflow records the failure in the table and stops.
Automation and scale
This pattern supports a single development environment only. To use it across multiple development environments, you must change the configuration.
To add support for more than one CloudFormation stack, you can create additional CloudFormation templates. For more information, see Getting started with AWS CloudFormation
in the CloudFormation documentation.
Tools
Tools
AWS Step Functions
is a serverless orchestration service that helps you combine AWS Lambda functions and other AWS services to build business-critical applications. AWS Lambda
is a compute service that helps you run code without needing to provision or manage servers. It runs your code only when needed and scales automatically, so you pay only for the compute time that you use. AWS CodeBuild
is a fully managed build service that helps you compile source code, run unit tests, and produce artifacts that are ready to deploy. AWS CodeCommit
is a version control service that helps you privately store and manage Git repositories, without needing to manage your own source control system. AWS CodePipeline
helps you quickly model and configure the different stages of a software release and automate the steps required to release software changes continuously. AWS Identity and Access Management (IAM)
helps you securely manage access to your AWS resources by controlling who is authenticated and authorized to use them. AWS Key Management Service (AWS KMS)
helps you create and control cryptographic keys to help protect your data. Amazon Simple Storage Service (Amazon S3)
is a cloud-based object storage service that helps you store, protect, and retrieve any amount of data. AWS CloudFormation
helps you set up AWS resources, provision them quickly and consistently, and manage them throughout their lifecycle across AWS accounts and Regions. Amazon DynamoDB
is a fully managed NoSQL database service that provides fast, predictable, and scalable performance. AWS Systems Manager Parameter Store
provides secure, hierarchical storage for configuration data management and secrets management.
Code
The code for this pattern is available in the GitHub automated-ci-pipeline-creation
Amazon CloudWatch Logs
Best practices
Don't enter credentials (secrets) such as tokens or passwords directly into AWS CloudFormation templates or Step Functions action configurations. If you do, the information appears in the Step Functions execution history and diagnostic logs. Instead, use AWS Secrets Manager to set up and store secrets. Then, reference the secrets stored in Secrets Manager within the CloudFormation templates and Step Functions action configurations as needed. For more information, see What is AWS Secrets Manager
in the Secrets Manager documentation. Configure server-side encryption for CodePipeline artifacts stored in Amazon S3. For more information, see Configure server-side encryption for artifacts stored in Amazon S3 for CodePipeline
in the CodePipeline documentation. Apply least-privilege permissions when configuring IAM roles. For more information, see Apply least-privilege permissions
in the IAM documentation. Make sure that your Amazon S3 bucket is not publicly accessible. For more information, see Configuring block public access setting for your S3 buckets
in the Amazon S3 documentation. Make sure that you activate versioning for your Amazon S3 bucket. For more information, see Using versioning in S3 buckets
in the Amazon S3 documentation. Use IAM Access Analyzer when configuring IAM policies. The tool provides actionable recommendations to help you author secure and functional IAM policies. For more information, see Using AWS Identity and Access Management Access Analyzer
in the IAM documentation. When possible, define specific access conditions when configuring IAM policies.
Activate Amazon CloudWatch logging for monitoring and auditing purposes. For more information, see What is Amazon CloudWatch Logs?
in the CloudWatch documentation. Restrict write access to the Amazon S3 bucket that holds the templates and the buildspec fragments. Anyone who can change the fragments changes what the generated pipelines run.
Don’t add secrets to the buildspec fragments. Use AWS Secrets Manager instead.
Epics
| Task | Description | Skills required |
|---|---|---|
Create an Amazon S3 bucket. | Create an Amazon S3 bucket (or use an existing bucket) to store the required AWS CloudFormation templates, source code, and input files for the solution. Block all public access to the bucket, and turn on default encryption and versioning. For more information, see Step 1: Create your first S3 bucket Note The Amazon S3 bucket must be in the same AWS Region where you deploy the solution. | AWS DevOps |
Clone the GitHub repository. | Clone the GitHub automated-ci-pipeline-creation
For more information, see Cloning a repository | AWS DevOps |
Upload the Solution Templates folder from the cloned GitHub repository to your Amazon S3 bucket. | Copy the contents from the cloned Solution-Templates folder and upload them into the Amazon S3 bucket that you created. For more information, see Uploading objects Note Make sure that you upload the contents of the Solution-Templates folder only. You can upload the files at the Amazon S3 bucket’s root level only. | AWS DevOps |
| Task | Description | Skills required |
|---|---|---|
Create a CloudFormation stack to deploy the solution by using the template.yml file in the cloned GitHub repository. |
Note While CloudFormation creates your stack, the stack appears on the Stacks page with a status of CREATE_IN_PROGRESS. Wait for the stack’s status to change to CREATE_COMPLETE before you complete the remaining steps in this pattern. | AWS administrator, AWS DevOps |
| Task | Description | Skills required |
|---|---|---|
Run the AWS Step Functions state machine that you created. |
JSON formatting
Note
Java JSON input example
Python JSON input example
| AWS administrator, AWS DevOps |
Confirm that the AWS CodeCommit repository for the CI pipeline was created. |
| AWS DevOps |
Check the AWS CodeBuild project resources. |
| AWS DevOps |
Validate the CodePipeline stages. |
| AWS DevOps |
Confirm that the CI pipeline ran successfully. |
| AWS DevOps |
| Task | Description | Skills required |
|---|---|---|
Delete the CI pipeline stack. |
| AWS DevOps |
Delete the CI pipeline’s dependencies. |
| AWS DevOps |
Delete the solution stack and the template bucket. |
| AWS DevOps |
Related resources
Creating a Step Functions state machine that uses Lambda
(AWS Step Functions documentation) AWS Step Functions Workflow Studio
(AWS Step Functions documentation) How does AWS CloudFormation work?
(AWS CloudFormation documentation) Complete CI/CD with AWS CodeCommit, AWS CodeBuild, AWS CodeDeploy, and AWS CodePipeline
(AWS blog post) IAM and AWS STS quotas, name requirements, and character limits
(IAM documentation) Docker images provided by CodeBuild
(AWS CodeBuild User Guide) Using CloudWatch Logs to log execution history in Step Functions
(AWS Step Functions Developer Guide)