aws-toolkit-azure-devops icon indicating copy to clipboard operation
aws-toolkit-azure-devops copied to clipboard

AWSCLI - Interact with the AWSCLI - linux build host

Open kierantrainor opened this issue 1 year ago • 0 comments

In the documentation it mentions the following :

AWSCLI - Interact with the AWSCLI (Windows hosts only)

Im using linux build host and it works fine, i just want to know why this line has been included in the documentation:

Reference: https://marketplace.visualstudio.com/items?itemName=AmazonWebServices.aws-vsts-tools

https://aws.amazon.com/blogs/devops/use-the-aws-toolkit-for-azure-devops-to-automate-your-deployments-to-aws/

I export the Credentials to use in later bash tasks

My task :

  • task: AWSShellScript@1 displayName: "Assume AWS Role" inputs: awsCredentials: "ado-connection"
    regionName: "eu-west-1" failOnStderr: true
    workingDirectory: "$(System.DefaultWorkingDirectory)" scriptType: 'inline' inlineScript: | # Set AWS Credentials and Assume Role
    echo "Current Identity" aws sts get-caller-identity

    role_arn="${{ parameters.assume_role }}"
    echo "Assuming role $role_arn"
    
    temp_role=$(aws sts assume-role --role-arn $role_arn --role-session-name Azure-Dev-Ops)
    
    AWS_ACCESS_KEY_ID=$(echo $temp_role | jq -r .Credentials.AccessKeyId)
    AWS_SECRET_ACCESS_KEY=$(echo $temp_role | jq -r .Credentials.SecretAccessKey)
    AWS_SESSION_TOKEN=$(echo $temp_role | jq -r .Credentials.SessionToken)
    
    echo "AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID"
    
    # Set environment variables for future tasks
    echo "##vso[task.setvariable variable=AWS_ACCESS_KEY_ID;isSecret=true]$AWS_ACCESS_KEY_ID"
    echo "##vso[task.setvariable variable=AWS_SECRET_ACCESS_KEY;isSecret=true]$AWS_SECRET_ACCESS_KEY"
    echo "##vso[task.setvariable variable=AWS_SESSION_TOKEN;isSecret=true]$AWS_SESSION_TOKEN"
    

kierantrainor avatar Oct 03 '24 10:10 kierantrainor