- Newest
- Most votes
- Most comments
I understand you're trying to set up an automated testing pipeline using pytest on an AWS EC2 Windows instance, triggered by Git commits. Here's a step-by-step guide to help you achieve this:
-
EC2 Windows Instance Setup:
- Ensure Python 3.6.1 or newer is installed on your Windows Server 2019 instance.
- Install pytest and any other required Python libraries.
- Install the AWS CLI and configure it with the appropriate credentials.
- Install Git on the instance if not already present.
-
IAM Role Configuration:
- Verify that the IAM role attached to your EC2 instance has the necessary permissions for CodeDeploy and any other AWS services you're using.
-
CodePipeline Setup:
- In the Source stage, confirm your Git repository is correctly linked.
- For the Build stage, add a CodeBuild project:
- Use a Windows container image.
- In the buildspec.yml, include commands to:
- Install required dependencies
- Run pytest
- Generate test reports
-
CodeDeploy Configuration:
- In your CodeDeploy application, create an AppSpec file (appspec.yml) in your repository root.
- Define the deployment process, including:
- File copying instructions
- Scripts to run before and after deployment
-
EC2 Instance Preparation:
- Install the CodeDeploy agent on your Windows EC2 instance.
- Ensure the instance is tagged properly for your CodeDeploy deployment group.
-
Monitoring and Logging:
- Set up CloudWatch Logs agent on your EC2 instance to stream logs.
- Configure your pytest execution to output detailed logs.
-
Trigger Setup:
- In your CodePipeline, ensure the pipeline is set to automatically trigger on Git commits.
-
Test Execution:
- Make a small change to your Git repository and commit it.
- Monitor the CodePipeline console to see the pipeline stages executing.
- Check the CodeBuild and CodeDeploy logs for detailed execution information.
- Access your EC2 instance and check the local logs for pytest execution details.
If you're still unable to see the executions properly, check the following:
- Verify all IAM roles have the correct permissions.
- Ensure the CodeDeploy agent is running on your EC2 instance.
- Check EC2 instance logs for any deployment or execution errors.
- Review the CodePipeline, CodeBuild, and CodeDeploy console for any failed steps or error messages.
Remember to iterate and troubleshoot each step individually. If a particular stage is failing, focus on resolving that before moving to the next. With proper setup and configuration, you should be able to see your pytest executions running automatically on your Windows EC2 instance whenever you make a Git commit.
Sources
Run unit tests for Python ETL jobs in AWS Glue using the pytest framework - AWS Prescriptive Guidance
Step 1: Prepare your environment for running the script - AWS OpsWorks
Run automation from console - Cloud Migration Factory on AWS
