Technical ‐ AWS ‐ Temporary infrastructure - Yves-Guduszeit/Interview GitHub Wiki
Temporary infrastructure on AWS refers to cloud resources that are provisioned for a specific purpose and a limited duration, after which they are automatically or manually deprovisioned to save costs and improve resource efficiency. This approach is widely used in DevOps, development, and testing workflows to ensure scalability and cost-effectiveness.
-
Development and Testing Environments:
- Create isolated environments for feature development, integration testing, or QA.
- Automatically tear down environments after testing is complete to minimize costs.
-
CI/CD Pipelines:
- Use temporary infrastructure for build, test, and deployment stages.
- Spin up ephemeral compute resources (e.g., EC2 instances or containers) to run jobs and terminate them once the job completes.
-
Data Processing and Batch Jobs:
- Provision compute instances or serverless resources (e.g., AWS Lambda) for batch processing or analytics workloads and deprovision them when done.
-
Disaster Recovery Drills:
- Temporarily replicate production environments to test failover mechanisms and disaster recovery strategies.
-
Temporary Demo or Training Environments:
- Spin up environments for customer demos or team training sessions and destroy them afterward.
-
Amazon EC2 Spot Instances:
- Cost-effective, short-lived compute resources that can be terminated when no longer needed.
- Ideal for non-critical workloads, batch jobs, or testing.
-
AWS Auto Scaling:
- Automatically scales compute resources (EC2 instances, ECS tasks, etc.) up or down based on load, and terminates instances when no longer required.
-
AWS CloudFormation:
- Enables the creation and teardown of entire infrastructure stacks using templates.
- Automate the provisioning of environments for repeatability.
-
AWS Lambda:
- Event-driven, serverless compute for running short-lived workloads without managing servers.
- Automatically scales and only incurs costs when invoked.
-
Amazon ECS and Fargate:
- Containerized workloads that can be quickly deployed and terminated as part of ephemeral environments.
-
AWS CodeBuild:
- Fully managed CI/CD build service that spins up temporary build environments for compiling code, running tests, and creating packages.
-
Amazon RDS (On-Demand or Aurora Serverless):
- On-demand or serverless databases that can be easily started and stopped based on requirements.
-
AWS Elastic Beanstalk:
- Simplifies the process of spinning up temporary environments for application hosting with automatic scaling and deployment.
-
S3 with Lifecycle Policies:
- Store data temporarily and automatically transition or delete objects after a defined period.
-
Infrastructure as Code (IaC):
- Use tools like AWS CloudFormation, Terraform, or AWS CDK to define and automate the creation and destruction of resources.
- Example: Define CI/CD pipelines that spin up test environments, run jobs, and delete the infrastructure automatically.
-
Automation with Tags:
- Tag resources with metadata (e.g.,
Environment: TemporaryorTTL: <timestamp>). - Use AWS Config or custom scripts to identify and clean up expired resources.
- Tag resources with metadata (e.g.,
-
Scheduled Start/Stop:
- Use AWS Instance Scheduler to start and stop resources like EC2 or RDS based on predefined schedules.
- Example: Shut down non-production environments during weekends to save costs.
-
Lambda Functions for Cleanup:
- Write AWS Lambda functions to automatically clean up resources based on lifecycle events or schedules.
-
Spot and Savings Plans:
- Use Spot Instances for temporary, non-critical workloads, and Savings Plans for predictable, temporary workloads.
-
Cost Optimization:
- Monitor costs with AWS Cost Explorer or AWS Budgets.
- Use Spot Instances and serverless options for unpredictable workloads.
-
Security:
- Automate the provisioning of temporary infrastructure with secure configurations, such as applying security groups and IAM policies.
- Leverage tools like AWS Secrets Manager or HashiCorp Vault to manage credentials.
-
Cleanup Mechanisms:
- Implement automatic cleanup for unused resources to avoid resource sprawl and unexpected costs.
-
Testing Strategies:
- Use staging and test environments that closely mimic production but are automatically destroyed after testing.
-
Monitoring and Logging:
- Enable CloudWatch for logging and monitoring of temporary resources to identify any issues during their lifecycle.
Use Case: CI/CD Pipeline for Automated Testing
- Trigger: A developer pushes code to the repository.
- Provision: A CI/CD pipeline (e.g., GitLab CI, AWS CodePipeline) uses Terraform or CloudFormation to spin up a testing environment, including EC2 instances, databases, and other resources.
- Execution: The pipeline runs automated tests on the temporary infrastructure.
- Tear Down: Once tests are complete, the pipeline destroys the temporary resources automatically.
This workflow ensures resource efficiency and maintains a clean, scalable, and cost-effective environment.