Run EC2 Scripts CI/CD Catalog project
Welcome to the Run EC2 Commands CI/CD Component Wiki!
Overview
The EC2 Run Script
component provides a streamlined way to manage EC2 instances directly within a GitLab CI/CD pipeline. It leverages AWS CLI commands to execute tasks such as running a script on EC2 instances stored in S3. The component allows users to configure environment variables and execute tasks with customizable logging and runner options.
Usage
The component is integrated into GitLab pipelines to automate the execution a script on EC2 instances. It leverages the AWS CLI and SSM to run commands securely without the need for direct network access. Additionally, it can handle AWS credential setup, log configuration, and runner tag management.
Inputs
- Log Level: Controls the verbosity of log output. You can select a lower level for minimal logs or increase it for detailed debugging information.
- Stage: Defines the pipeline stage where the job runs, such as build, test, or deploy.
- Runner Tags: Specifies which GitLab runners should be used for executing the job, providing flexibility in pipeline execution.
- Instance ID: The EC2 instance(s) on which the commands or scripts will be executed.
- s3-bucket-name: The name of the S3 bucket where the script will be copied to before executing it on the EC2 instance(s).
- Script Path: The path to the script to be uploaded and executed on the EC2 instance(s).
AWS CLI and Credential Management
The component ensures that AWS CLI is installed and properly configured before any operations are performed. It sets up AWS credentials using environment variables, validating their correctness before proceeding. If credentials are missing or invalid, it will log an error and exit to prevent unauthorized access.
Logging Configuration
The component allows you to configure the logging level to control the detail shown in the pipeline output. If you prefer minimal output, you can set the log level to a lower value. For more detailed logs, including debugging information, you can increase the log level to gain better insights into the pipeline's execution.
EC2 Operations
The component offers two primary operations:
- Running Scripts on EC2: The component allows you to upload a script to an S3 bucket, which is then executed on the EC2 instance(s) via AWS SSM. This is particularly useful for running complex tasks that are better suited to scripts rather than individual commands.
Common Use Cases
- EC2 Instance Automation: Automating the execution of a shell script on EC2 instances during the CI/CD process.
- Secure Script Execution: Running scripts on EC2 instances without needing SSH access, leveraging SSM and S3 for secure, auditable interactions.
- Pipeline Infrastructure Setup: Using EC2 instances for testing, deployment, or operational purposes within the CI/CD pipeline, managed directly from the pipeline's GitLab configuration.
Conclusion
The Run EC2 Script
component provides a powerful and secure way to interact with EC2 instances in GitLab CI/CD pipelines. It supports running a bash script via AWS SSM, ensuring security and ease of use. With AWS credential management, configurable logging, and flexible runner tags, the component simplifies EC2 instance automation within your pipeline.