A Guide to Installing and Configuring Sceptre
Tags: infrastructureascode, devops, sceptre, cloudformation
Published: 2023-07-27 00:32:47


![Installing Sceptre](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7zw721xxfjrokmphlw9l.png)



Sceptre, an open-source tool developed by Cloudreach, offers a robust solution for managing cloud infrastructure as code. In this article, we will explore various methods of installing and configuring Sceptre, including using Docker, based on the official [Sceptre documentation](https://docs.sceptre-project.org/latest/docs/install.html).

## Installation

### Installing Sceptre via pip (Python Package Manager)

The simplest way to install Sceptre is using pip, the Python package manager. First, ensure you have Python installed on your system

Prerequisites

 1. AWS Account: You will need an AWS account to work with Sceptre since it interacts with CloudFormation and other AWS services.

 2. Python: Sceptre requires Python, so ensure you have Python (version 3.6+) installed on your system.

Now that we have the prerequisites covered, let’s proceed with installing Sceptre:

 1. Open your terminal or command prompt.

 2. Use pip to install Sceptre by running the following command:

   ` pip install sceptre`

![](https://cdn-images-1.medium.com/max/2268/1*vSxsd1V7BwTaOr3O3UaLww.jpeg)

3. Wait for the installation to complete, and you’re now ready to use Sceptre.

4. Once the installation is complete, you can verify it by running

    `sceptre --version`

![](https://cdn-images-1.medium.com/max/2268/1*fXKJzEIkLNf4pV81x_zkIg.jpeg)

### Configuring Sceptre

With Sceptre installed, the next step is to set up the necessary configuration:

 1. Configuring AWS Credentials for Sceptre

Sceptre uses the standard AWS SDK for Python (Boto3) to interact with AWS services, and it follows the same credential resolution order as Boto3. The AWS credentials can be specified in multiple ways, and Sceptre automatically picks up the appropriate credentials based on this order:

**i.) Environment Variable**s: Sceptre checks for the presence of the following environment variables:

AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY : Specifies the AWS access key ID and secret access key.
AWS_SESSION_TOKEN: Specifies the session token for temporary security credentials when using AWS Identity and Access Management (IAM) roles.

**ii.) AWS Config File**: Sceptre looks for the AWS configuration file (~/.aws/config) that can define multiple profiles, each with its set of credentials. The [default] profile is used if no specific profile is specified.

**iii.) AWS Credentials File**: Sceptre checks for the AWS credentials file (~/.aws/credentials), which can also define multiple profiles with their respective credentials.

**iv.) IAM Role for Amazon EC2 Instance**: If Sceptre is running on an Amazon EC2 instance, it automatically retrieves the credentials associated with the IAM role attached to that EC2 instance.

**v.) IAM Role via Instance Metadata Service**: If Sceptre is running on an Amazon EC2 instance and there is no IAM role directly attached to the instance, it will check the instance metadata service to determine if there is an IAM role associated with the EC2 instance.

**vi.) AWS CLI Configuration**: If you have configured the AWS CLI with aws configure, Sceptre will also pick up the credentials from the CLI configuration.

**vii) Explicitly Defined Credentials**: You can explicitly define credentials in your Sceptre configuration files (config/*.yaml). By specifying a profile name or providing access key ID, secret access.

>     It’s important to note that the credentials specified explicitly in the Sceptre configuration files or directly in the AWS CLI commands take precedence over other methods for credential resolution.
>     By following this order, Sceptre ensures that it can automatically access the correct AWS credentials based on the environment or explicit settings, making it easier for users to manage and deploy AWS resources with different sets of credentials in various scenarios.

2. Creating the directory structure for a new Sceptre project

Sceptre provides a convenient command, sceptre new, which can be used to create the directory structure and initial configuration files for a new Sceptre project. This command streamlines the setup process and ensures that you start with a well-organized project layout. To create a new Sceptre project using the sceptre new command, follow these steps:

 1. Open your terminal or command prompt.

 2. Navigate to the location where you want to create the new Sceptre project directory.

 3. Run the following command:

       
    `sceptre new project first-sceptre-project`

![](https://cdn-images-1.medium.com/max/3664/1*_fvJ8gCCucqpgOj0WR8ovA.jpeg)

The above command will result in the following directory structure:

    
      my_sceptre_projects
      ├──first-sceptre-project
         ├── config
         │   └── config.yaml
         └── templates
>  In the Sceptre project, you will find the configuration directory where you can store the configurations for your Stacks, and the templates directory is designated for holding your CloudFormation templates

### Using Docker for Sceptre

For those who prefer containerization, running Sceptre in a Docker container is an excellent option. First, ensure you have Docker installed on your system.

To pull the official Sceptre Docker image from Docker Hub, use the following command:

    `docker pull cloudreach/sceptre`

![](https://cdn-images-1.medium.com/max/3664/1*qyYufrQNiHzWGKqaf8yyqg.jpeg)

After downloading the image, either create a new directory for your Sceptre project or navigate to the existing project directory in your terminal. Let’s navigate to the Sceptre project directory named “first-sceptre-project” that was created in a previous step.

   ` cd first-sceptre-project`

Now, you can run Sceptre commands inside the Docker container using the following syntax:

    `docker run -v "$(pwd)":/project -w /project cloudreach/sceptre [sceptre-command]`

For example, to check the sceptre version, run:

    `docker run -v "$(pwd)":/project -w /project cloudreach/sceptre --version`

![](https://cdn-images-1.medium.com/max/4376/1*_JTFX9_kkB0uWlutf3cbyg.jpeg)
>  This command mounts your current project directory inside the container and sets it as the working directory for Sceptre commands.

If a custom ENTRYPOINT is desired, you can modify the Docker command accordingly:

   ` docker run --entrypoint='' -it --rm -v "$(pwd)":/project -w /project cloudreach/sceptre sh`
>  By running the command above, you will enter the Docker container’s shell, allowing you to execute Sceptre commands, which is particularly useful for development purposes.

Instead of pulling down the Sceptre Docker image from Dockerhub, an alternative approach is to build a custom Docker image.

Create a Dockerfile with the following content:

   

```
 FROM python:3.9
    
 RUN pip install sceptre

 ENTRYPOINT ["sceptre"]
```

Next, build the Docker image by running:

   ` docker build -t sceptre-image .`

With our custom-built Docker image ready, we can now utilize it to execute Sceptre commands in our project directory, as previously explained in the steps.

### Conclusion

Sceptre provides a robust and flexible solution for managing cloud infrastructure as code. In this article, we explored various methods of installing and configuring Sceptre, including running it inside a Docker container. The pip installation method is straightforward and is ideal for those who prefer working directly on their system. On the other hand, Docker offers a containerized approach, providing isolation and consistency for Sceptre commands.

Regardless of the method you choose, Sceptre simplifies cloud infrastructure management, enabling you to define, deploy, and manage AWS resources efficiently. Incorporate Sceptre into your workflow to unleash the true potential of cloud infrastructure as code and take your cloud management practices to new heights.

Remember to consult the official Sceptre documentation for more advanced features and customization options. Happy coding!