Skip to content

Powershell scripts for automatic authentication with AWS CodeArtifact on nuget cli and AWS ECR with Docker. Supports cross-platform execution (Windows, macOS, and Linux)

License

Notifications You must be signed in to change notification settings

karimz1/AWS-Authentication-Scripts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AWS Authentication Scripts

Overview

Welcome to the AWS Authentication Scripts repository! This project contains PowerShell scripts designed to streamline the authentication process for AWS services like CodeArtifact and ECR. These scripts will help you log into each service and update necessary tokens or credentials, with detailed logging for easy auditing and troubleshooting.

Features

  • Authenticate and log into AWS CodeArtifact repositories.
  • Authenticate Docker with AWS ECR.
  • Cross-platform compatibility (Windows, macOS, and Linux).

Prerequisites

  • AWS CLI installed and configured. For more information, refer to the AWS CLI Installation Guide and Configuring the AWS CLI.
  • Docker installed (for ECR authentication).
  • PowerShell Core (7.x) installed.
  • Access to the AWS CodeArtifact and ECR services.
  • Proper configuration of AWS credentials and region.

Installation

  1. Clone or download the repository containing the scripts.

Usage

Refresh NuGet Tokens for AWS CodeArtifact

  1. Open PowerShell Core and navigate to the directory containing the refreshNugetTokens.ps1 script.
  2. Run the script using the following command:
    .\refreshNugetTokens.ps1
    
    

Authenticate Docker with AWS ECR

  1. Open PowerShell Core and navigate to the directory containing the refreshEcrDockerToken.ps1 script.
  2. Run the script using the following command:
    .\refreshEcrDockerToken.ps1

Automate with Cron Jobs or Task Scheduler

To ensure that your development machine is always authenticated with the necessary services, feel free to add these scripts to your cron jobs (Linux/macOS) or Task Scheduler (Windows). This way, you can automate the authentication process to run at startup or at regular intervals.

Cron Job Example (Linux/macOS)

  1. Open your crontab configuration:
crontab -e    
  1. Add the following line to run the script at startup (adjust the path as needed):
@reboot pwsh /path/to/the/repository/refreshNugetTokens.ps1    
@reboot pwsh /path/to/the/repository/refreshEcrDockerToken.ps1    

Task Scheduler Example (Windows)

  1. Open Task Scheduler and create a new task.

  2. Set the trigger to run the task at login.

  3. Set the action to start a program and use the following settings:

    "pwsh C:\path\to\the\repository\refreshNugetTokens.ps1"

  4. same for the other scripts if you need it.

Script Configuration

Both scripts contain configuration variables that can be modified as needed:

  • REGION: The AWS region where the service is hosted. Default is us-east-1.
  • DEBUG: Boolean to enable or disable debug mode. Default is false.

Example Configuration

# start Configuration
$REGION = "us-east-1"
$DEBUG = $false
# end Configuration

Adding More Authentication Mechanisms

Currently, this repository includes authentication scripts for AWS CodeArtifact and AWS ECR. If you have other authentication mechanisms to add, feel free to contribute!

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contributing

Hi, I'm Karim Zouine, the developer of these scripts. Contributions are very welcome! If you have suggestions, improvements, or bug fixes, please open an issue or submit a pull request. Let's make this project even better together!

About

Powershell scripts for automatic authentication with AWS CodeArtifact on nuget cli and AWS ECR with Docker. Supports cross-platform execution (Windows, macOS, and Linux)

Topics

Resources

License

Stars

Watchers

Forks