└── README.md /README.md: -------------------------------------------------------------------------------- 1 | # mediocre-cloud9 2 | 3 | This is my collection of mediocre Cloud9 tips. 4 | 5 | # Table of Contents 6 | 7 | - [CodeBuild](#Codebuild) 8 | - [CDK](#CDK) 9 | - [AWS SAM](#AWS-SAM) 10 | - [Python](#Python) 11 | - [GitHub and SSH](#GitHub-and-SSH) 12 | - [Hugo](#Hugo) 13 | - [Corretto](#Corretto) 14 | - [Extra](#Extra) 15 | 16 | --- 17 | 18 | ## CodeBuild 19 | 20 | ### [CodeBuild Local](https://github.com/aws/aws-codebuild-docker-images) 21 | I want to test my `buildspec.yml` file wasting a bunch of time/money on actually running CodeBuild. 22 | 23 | 24 | ```bash 25 | git clone https://github.com/aws/aws-codebuild-docker-images.git 26 | cd aws-codebuild-docker-images 27 | cd al2/x86_64/standard/3.0 28 | # cd al2/aarch64/standard/2.0/ If you are Matthew S. Wilson 29 | docker build --tag codebuild:001 . 30 | # wait a literal eternity 31 | DOCKER_ID=$(docker images codebuild:001 --format "{{.ID}}") 32 | cd /your/local/code/directory 33 | path/to/aws-codebuild-docker-images/local-builds/codebuild_build.sh -i $DOCKER_ID -a $(pwd)/artifacts -m -p isengard_example 34 | ``` 35 | 36 | ### CDK 37 | 38 | #### Building CDK Constructs with Cloud9 39 | 40 | ```bash 41 | GITHUB_ALIAS=richardhboyd 42 | # Get the latest version of Node 43 | VERSION=$(nvm ls-remote --lts | grep Latest | tail -1 | grep -o "\(v[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\)") 44 | nvm install $VERSION 45 | # Just to be safe, let's grab the latest typescript 46 | npm uninstall -g typescript 47 | npm install -g typescript 48 | 49 | # Apparently dotnet is needed now too 50 | sh -c "$(curl -fsSL https://dot.net/v1/dotnet-install.sh)" 51 | export PATH=$PATH:/home/ec2-user/.dotnet 52 | 53 | git clone git@github.com:$GITHUB_ALIAS/aws-cdk.git 54 | cd aws-cdk/ 55 | git remote add upstream https://github.com/aws/aws-cdk.git 56 | # If you've diverged, I usually check out the last common commit 57 | # git checkout [HASH] 58 | git fetch upstream 59 | git merge upstream/master 60 | git checkout -b feature_branch 61 | # Make your changes 62 | docker build -t aws-cdk . 63 | ``` 64 | 65 | ## AWS SAM 66 | 67 | ### Update SAM 68 | 69 | ```bash 70 | # sudo localedef -i en_US -f UTF-8 en_US.UTF-8 # Likely not needed 71 | # Need the exports for env filtering due to issue in Brew 72 | # https://github.com/Linuxbrew/brew/issues/568#issuecomment-357527644 73 | # /home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/brew.sh: line 15: warning: setlocale: LC_ALL: cannot change locale (C.UTF-8): No such file or directory 74 | # /home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/brew.sh: line 15: warning: setlocale: LC_ALL: cannot change locale (C.UTF-8) 75 | export HOMEBREW_NO_ENV_FILTERING=1 76 | CI=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" 77 | test -d ~/.linuxbrew && eval $(~/.linuxbrew/bin/brew shellenv) 78 | test -d /home/linuxbrew/.linuxbrew && eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv) 79 | test -r ~/.bash_profile && echo -e "export HOMEBREW_NO_ENV_FILTERING=1\neval \$($(brew --prefix)/bin/brew shellenv)" >>~/.bash_profile 80 | echo -e "export HOMEBREW_NO_ENV_FILTERING=1\neval \$($(/home/linuxbrew/.linuxbrew/bin/brew --prefix)/bin/brew shellenv)" >>~/.profile 81 | npm uninstall -g aws-sam-local 82 | sudo pip uninstall aws-sam-cli -y 83 | sudo rm -rf $(which sam) 84 | brew tap aws/tap 85 | brew install aws-sam-cli 86 | ln -sf $(which sam) ~/.c9/bin/sam 87 | ls -la ~/.c9/bin/sam 88 | ``` 89 | 90 | ## Python 91 | 92 | ### Update Python Version 93 | 94 | ```bash 95 | sudo -u root -s 96 | VERSION=3.7.4 97 | INSTALL_DIR=/usr/local 98 | sudo yum update -y 99 | sudo yum install gcc openssl-devel bzip2-devel libffi-devel -y 100 | wget https://www.python.org/ftp/python/${VERSION}/Python-${VERSION}.tgz 101 | tar xzf Python-${VERSION}.tgz 102 | cd Python-${VERSION} 103 | ./configure --prefix=${INSTALL_DIR} 104 | make -j $(nproc) 105 | make install -j $(nproc) 106 | cd ../ 107 | ### DANGER ZONE, this will break parts of Cloud9 108 | # Remove old symlinks 109 | rm -rf /etc/alternatives/pip 110 | rm -rf /etc/alternatives/python 111 | # make new symlinks 112 | ln -s ${INSTALL_DIR}/bin/pip${VERSION:0:3} /etc/alternatives/pip 113 | ln -s ${INSTALL_DIR}/bin/python${VERSION:0:3} /etc/alternatives/python 114 | ### END DANGER ZONE 115 | exit 116 | #TODO add /home/ec2-user/.local/lib/python3.8/site-packages to 'special' PATH 117 | ``` 118 | 119 | ## GitHub and SSH 120 | 121 | ### SSH Keys 122 | From my laptop I run 123 | 124 | ```bash 125 | HOME_DIR=~ 126 | aws secretsmanager create-secret --name dev/github/richardhboyd --secret-string file://${HOME_DIR}/.ssh/github --region us-west-2 --profile federate 127 | ``` 128 | 129 | Then I can run this from my Cloud9 Environment to fetch and set the SSH Keys. 130 | 131 | ```bash 132 | HOME_DIR=/home/ec2-user/ 133 | git config --global user.name "Richard Boyd" 134 | git config --global user.email rhboyd@amazon.com 135 | # Add your private key 136 | aws secretsmanager get-secret-value --secret-id dev/github/richardhboyd --query "SecretString" --output text --region us-west-2 > ${HOME_DIR}.ssh/github 137 | 138 | #restrict the access to the keys 139 | chmod 400 ${HOME_DIR}.ssh/github 140 | 141 | echo "IdentityFile ${HOME_DIR}.ssh/github" > ${HOME_DIR}.ssh/config 142 | chmod 400 ${HOME_DIR}.ssh/config 143 | ``` 144 | 145 | ## Hugo 146 | 147 | ### Running Hugo on Cloud9 148 | 149 | ``` 150 | wget https://github.com/gohugoio/hugo/releases/download/v0.62.1/hugo_0.62.1_Linux-64bit.tar.gz 151 | tar -xvzf hugo_0.62.1_Linux-64bit.tar.gz 152 | sudo mv hugo /usr/local/bin/ 153 | 154 | REGION=$(curl -s http://169.254.169.254/latest/dynamic/instance-identity/document | sed -n 's/.*"region" : "\([a-z0-9-]*\)",/\1/p') 155 | PREVIEW_URL="https://$C9_PID.vfs.cloud9.$REGION.amazonaws.com/" 156 | hugo serve --bind=0.0.0.0 -p 8080 -b $PREVIEW_URL --appendPort=false --disableFastRender 157 | ``` 158 | 159 | ## Corretto 160 | 161 | ### Corretto 11/15 162 | 163 | ```bash 164 | sudo -u root -s 165 | JAVA_VERSION=15 166 | curl -L -o /etc/yum.repos.d/corretto.repo https://yum.corretto.aws/corretto.repo 167 | yum install -y java-${JAVA_VERSION}-amazon-corretto-devel 168 | exit 169 | ``` 170 | 171 | ### Maven 172 | ```bash 173 | sudo -u root -s 174 | wget http://repos.fedorapeople.org/repos/dchen/apache-maven/epel-apache-maven.repo -O /etc/yum.repos.d/epel-apache-maven.repo 175 | sed -i s/\$releasever/6/g /etc/yum.repos.d/epel-apache-maven.repo 176 | yum install -y apache-maven 177 | exit 178 | ``` 179 | ## Extra 180 | 181 | ### Links to examples of people using Cloud9 182 | - AWS Cloud9 [Launch Blog](https://aws.amazon.com/blogs/aws/aws-cloud9-cloud-developer-environments/) by [Randall Hunt](https://twitter.com/jrhunt) 183 | - [Field Notes: Optimize your Java application for AWS Lambda with Quarkus](https://aws.amazon.com/blogs/architecture/field-notes-optimize-your-java-application-for-aws-lambda-with-quarkus/) by [Sascha Moellering](https://twitter.com/sascha242) and [Steffen Grunwald](https://twitter.com/steffeng) 184 | - [How to Run Headless Front-End Tests with AWS Cloud9 and AWS CodeBuild](https://aws.amazon.com/blogs/devops/how-to-run-headless-front-end-tests-with-aws-cloud9-and-aws-codebuild/) by [Eric Beard](https://twitter.com/EricZBeard) 185 | - [Deploying a serverless application using AWS CDK](https://aws.amazon.com/blogs/devops/deploying-a-serverless-application-using-aws-cdk/) by [Georges Leschener](https://www.linkedin.com/in/georges-leschener-6872458/) and [Luis Lopez Soria](https://www.linkedin.com/in/luis-l-5005718b/) 186 | - [Building a Meeting Application using the Amazon Chime SDK](https://aws.amazon.com/blogs/business-productivity/building-a-meeting-application-using-the-amazon-chime-sdk/) by Doug Lawty 187 | --------------------------------------------------------------------------------