Using locally stored configuration files in dev container features

162 views Asked by At

I am looking into dev containers in visual studio code and possible features like CLI's, like the AWS CLI: https://github.com/devcontainers/features/tree/main/src/aws-cli.

Is it possible to install this in a manner that it will look for the configuration file that holds the credentials to login to the AWS account on the local file system (not the file system of the container)?

Asking this question due to the fact that I use SSO to login to my AWS account, and the configuration for this is stored on my local file system, and is not something that should be checked in into a remote repository.

1

There are 1 answers

1
Sachin Jariyal On

Yes, it is possible to configure AWS CLI in a dev container in Visual Studio Code to use credentials stored on your local file system. You can achieve this by mounting the local AWS configuration files into the container. Here are the steps:

  1. Mount the AWS configuration files: In your dev container configuration or Dockerfile, ensure that you mount the directory containing your AWS configuration files into the container. For example:

    ```Dockerfile
    FROM mcr.microsoft.com/vscode/devcontainers/python:3.9
    
    # Mount the AWS configuration directory
    COPY .aws /root/.aws
    ```
    

    Ensure that your .aws directory on the local machine contains the necessary configuration files, including config and credentials with your SSO settings.

  2. Configure AWS CLI to use the local files: Inside your dev container, make sure that the AWS CLI is configured to use the mounted files. You can set the AWS_SHARED_CREDENTIALS_FILE and AWS_CONFIG_FILE environment variables:

    ```Dockerfile
    ENV AWS_SHARED_CREDENTIALS_FILE=/root/.aws/credentials
    ENV AWS_CONFIG_FILE=/root/.aws/config
    ```
    

    This ensures that AWS CLI looks for credentials and configuration in the specified paths.

  3. Ensure proper permissions: Make sure that the mounted files have the necessary permissions for the container to read them.

With these configurations, the AWS CLI inside your dev container will use the AWS configuration files from your local machine, allowing you to leverage SSO without storing sensitive information in your remote repository.