Rick Cogley's Tech Logr

Short Technical Laser Bursts %%

RC Logr 20200627 103837

Saturday, 27 Jun, 2020

If you are using the aws cli tool, you can set the shell env var «AWS_PROFILE» to match your setup profile names linking to specific IAM credentials. 🍺 Here it is in a zsh function.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
function hugodeploy-coolsite (){
    echo "====== Deploy coolsite.jp site to AWS S3 ======"
    _hugobin="$HOME/gocode/bin/hugo"
    _awsbin="/usr/local/bin/aws"
    _workingdir="$HOME/dev/coolsite.jp"
    _current_aws_profile="$AWS_PROFILE"
    cd ${_workingdir}
    export AWS_PROFILE="deploy-coolsite"
    echo "🍺 Confirm aws profile via \"aws configure list\""
    ${_awsbin} configure list
    echo "🍺 Build and deploy site"
    ${_hugobin} && ${_hugobin} deploy --invalidateCDN --target coolsitejp --verbose
    [[ -z "$_current_aws_profile" ]] && unset AWS_PROFILE || export AWS_PROFILE=${_current_aws_profile}
}

This function sets some local vars, sets AWS_PROFILE via export then confirms it is set, then builds and deploys the site via hugo and hugo deploy. The site has a config file with the “coolsitejp” target, and under that is specified which AWS S3 bucket to deploy to. Use export instead of a simple assignation like I am doing with _hugobin etc, because you want to have the variable ready for use when the script invokes hugo to build and deploy the site. The last line unsets AWS_PROFILE for good measure if it was not set already, or resets it to whatever it was set to initially.

RC Logr 20200627 103837 - If you are using the aws cli … Rick Cogley
Back to Home Tweet Link