DEV Community

Cover image for How to Automatically Generate Tokens for CodeArtifact (Maven) in Windows
Federico Navarrete
Federico Navarrete

Posted on • Edited on • Originally published at supernovaic.blogspot.com

7 3

How to Automatically Generate Tokens for CodeArtifact (Maven) in Windows

If you have ever used or plan to use CodeArtifact, you will need to generate a token (CODEARTIFACT_AUTH_TOKEN) manually with all Maven projects daily. This can be challenging and slow down your development.

After a while, I came up with PowerShell Script that can simplify your work, creating a User Variable:

$AWS_ACCOUNT_ID='ID'
$DOMAIN='CODE_ARTIFACT_DOMAIN'
$env:CODEARTIFACT_AUTH_TOKEN = aws codeartifact get-authorization-token --domain $DOMAIN --domain-owner $AWS_USER_ACCOUNT --query authorizationToken --output text

Enter fullscreen mode Exit fullscreen mode

You only need to modify these two variables:

  • $AWS_ACCOUNT_ID, you get it from here:

account

  • $DOMAIN, you get it from here:

domain

After this, you can save the script as a .ps1 file and run it from PowerShell using this command:

powershell -ExecutionPolicy Bypass -File "MY_PATH\UpdateTokenNoAdmin.ps1"
Enter fullscreen mode Exit fullscreen mode

MY_PATH represents the location where you saved your file.

The last part is automating its recreation daily, for this, we are going to use the Task Scheduler:

scheduler

The first step, create a new task:

task

Then, you give it a name:

name

Next, you configure a trigger (I prefer at log on, but it can be daily):

logon

Finally, you add a new Action based on the previous command:

powershell -ExecutionPolicy Bypass -File "MY_PATH\UpdateTokenNoAdmin.ps1"
Enter fullscreen mode Exit fullscreen mode

action

And that's all, now, your env variable (CODEARTIFACT_AUTH_TOKEN) is going to be autogenerated!

Follow me on:

Personal LinkedIn YouTube Instagram Cyber Prophets Sharing Your Stories
Personal LinkedIn YouTube Instagram RedCircle Podcast RedCircle Podcast

sponsor me

Banner Credits:

AWS

Image of Datadog

How to Diagram Your Cloud Architecture

Cloud architecture diagrams provide critical visibility into the resources in your environment and how they’re connected. In our latest eBook, AWS Solution Architects Jason Mimick and James Wenzel walk through best practices on how to build effective and professional diagrams.

Download the Free eBook

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more