This has to be run with an environment that has awscli
pre-installed AND configured
- Sign up for a Github Account
- Generate a Github Personal Access Token like this
- In the list of
scopes
, make sure you only selectpublic_repo
- In the list of
- Make sure you copy the Github Token somewhere on your host machine. It is not visible once you navigate away from the page/refresh the page
- Open the lab image and open terminal in the IDE
cd /root
git clone https://github.com/we45/pr-step-function-pipeline
cd /root/pr-step-function-pipeline
aws ssm put-parameter --name "auth_token " --value "<copied token value>" --type "SecureString"
sls deploy
Wait for the Stack to be deployed
Copy the URL that is returned after the deployment process
-
In Github create a new project called "python-pr-example" and make sure to leave it private
-
Use this link to setup a project webhook for the project. Make sure:
- you set the content-type to
application/json
- Paste the URL generated from your
sls deploy
as the webhook URL - You can leave the
Secret
field empty although you should not do so in production - Ensure that you only select the
Pull Request
option from the webhook events
- you set the content-type to
- Once the webhook is setup, go back to your terminal in the lab image
In the terminal
cd /root
git clone https://github.com/<your-user-name>/python-pr-example
cd /root/python-pr-example
- Ensure you substitute
<your-user-name>
with your github username
Now lets create an obviously insecure python code snippet.
import hashlib
password = "hello world"
hash_value = hashlib.md5(password).hexdigest()
- Copy the contents of the above into a file and save it as
hello.py
Now create another file
echo "pyjwt==1.5.0" > requirements.txt
- Create a branch and push it to github
git checkout -b test
git push -u origin test
Now go over to github and make a pull request.
Make sure the compare
branch is set to test
and the base branch is master
Once you are done click on the create pull request
button
You should see your step functions run and write results to the PR in a few seconds.