As cloud-native architectures become the norm, managing infrastructure as code (IaC) is no longer a luxury, it's a necessity. While tools like the Serverless Framework are popular for abstracting infrastructure, Sceptre stands out for its tight integration with AWS CloudFormation and its flexibility in complex, real-world use cases.
In this post, we’ll:
- Use Sceptre to provision infrastructure
- Build a simple Python service
- Containerize it with Docker
- Set up Jenkins for CI/CD
- Briefly explore why Sceptre may be preferable to the Serverless Framework
Why Sceptre over Serverless Framework?
Sceptre is especially suited for teams who:
- Need infrastructure flexibility (beyond Lambda/APIs)
- Want full access to AWS resource definitions
- Deploy to multiple environments (dev, test, prod) in a structured way
Step 1: Write a Simple Python Script
Here’s the application logic — a basic Python script to be run in the cloud:
#script.py import time print("Python task started...") time.sleep(3) print("Task completed successfully!")
Use cases:
- Automation tasks
- Data processing
- Scheduled jobs
- Infrastructure hooks
Step 2: Dockerize It
To run this in ECS, we need to containerize the script:
# Dockerfile FROM python:3.10-slim WORKDIR /app COPY script.py . CMD ["python", "script.py"] Build and test: docker build -t python-task . docker run python-task
Step 3: Use Sceptre to Deploy to ECS Fargate
Sceptre lets us manage AWS infrastructure using CloudFormation templates and environment-specific configurations.
Directory Structure
infra/
├── config/
│ └── dev/
│ └── python-task.yaml
└── templates/
└── ecs-task.yaml
#config/dev/python-task.yaml template_path: templates/ecs-task.yaml stack_name: python-task parameters: TaskName: python-script-task ContainerImage: <YOUR_ECR_IMAGE_URL>
templates/ecs-task.yaml (CloudFormation) Resources: TaskDefinition: Type: AWS::ECS::TaskDefinition Properties: Family: !Ref TaskName Cpu: '256' Memory: '512' RequiresCompatibilities: [FARGATE] NetworkMode: awsvpc ExecutionRoleArn: arn:aws:iam::<ACCOUNT_ID>:role/ecsTaskExecutionRole ContainerDefinitions: - Name: python-container Image: !Ref ContainerImage Essential: true LogConfiguration: LogDriver: awslogs Options: awslogs-group: /ecs/python-task awslogs-region: !Ref AWS::Region awslogs-stream-prefix: python-task
Deploy with Sceptre :
cd infra
sceptre launch dev/python-task.yaml
Once launched, you can run this task using AWS CLI or trigger it via EventBridge for scheduled executions.
Step 4: Automate Deployment with Jenkins
Here's a minimal Jenkinsfile to automate the entire flow:
pipeline { agent any environment { ECR_REPO = "<ACCOUNT_ID>.dkr.ecr.<REGION>.amazonaws.com/python-task" } stages { stage('Build') { steps { sh 'docker build -t python-task .' } } stage('Push to ECR') { steps { sh ''' aws ecr get-login-password | docker login --username AWS --password-stdin $ECR_REPO docker tag python-task:latest $ECR_REPO:latest docker push $ECR_REPO:latest ''' } } stage('Deploy Infra') { steps { dir('infra') { sh 'sceptre launch dev/python-task.yaml' } } } } }
One push to Git, and Jenkins takes care of:
- Building your container
- Publishing it to ECR
- Updating your ECS TaskDefinition via Sceptre
Summary
You now have a repeatable, production-grade deployment pattern for running Python tasks in AWS with full control and no unnecessary abstraction.
Sceptre is not a replacement for Serverless Framework, but an empowering alternative when you want low-level control and native AWS CloudFormation integration. For teams who treat infrastructure as a first-class citizen, Sceptre is a great fit.
Useful References :
- Sceptre Documentation
- Docker Basics
- AWS ECS Task Definition Docs
- Jenkins Pipeline Docs
- AWS CLI: Run ECS Task
Disclaimer: This is a personal blog. The views and opinions expressed here are only those of the author and do not represent those of any organization or any individual with whom the author may be associated, professionally or personally.
Top comments (0)