loading...
Cover image for CI/CD to AWS with GitHub Actions

CI/CD to AWS with GitHub Actions

gautemeekolsen profile image Gaute Meek Olsen ・2 min read

Twitter bot with Kotlin in AWS (7 Part Series)

1) Twitter Bot - Vue 3 Updates 2) Creating an AWS Lambda Kotlin function 3 ... 5 3) Schedule our Lambda function 4) DynamoDB for our Kotlin Lambda function 5) Posting a tweet from Kotlin 6) Secrets in AWS and reading from Kotlin 7) CI/CD to AWS with GitHub Actions

This article is part of the Twitter bot with Kotlin in AWS series showing how I created a Twitter bot for Vue 3 updates. But this article works as an independent article on how to automatically deploy to AWS from your GitHub repository.

Now let's wrap it up by setting up continuous build and deploy of our Kotlin Lambda function to AWS. This will make sure the Lambda function is always up to date with the code in the master branch, no need to manually deploy your changes.

AWS IAM User

First, we need an IAM user. If you already have one, you can use the existing Access key ID and Secret access secret key. Or you can just click the "Create access key" button and generate new tokens.

GitHub Actions

We need to add two secrets to the GitHub repository. Go to your repository, click the "Settings" tab, and then "Secrets" in the side menu. Add the secrets AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY from the IAM user.

Luckily the GitHub Actions run on machines with a lot of software pre-installed, which includes the AWS CLI and Gradle.

Now head to "Actions" in the tab menu. Click "Set up this workflow" from any template. Add this yml code, that will setup Gradle, configure the AWS CLI, build the project, and update the function.

name: CI/CD

on:
  push:
    branches: [ master ]

jobs:
  CI-CD:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2

    - name: Gradle setup
      run: gradle wrapper
    - name: Build & Deploy
      run: |
        aws configure set aws_access_key_id ${{ secrets.AWS_ACCESS_KEY_ID }}
        aws configure set aws_secret_access_key ${{ secrets.AWS_SECRET_ACCESS_KEY }}
        aws configure set default.region eu-west-1
        ./gradlew build
        aws lambda update-function-code --function-name twitter-bot-vue-3 --zip-file fileb://build/libs/twitter-bot-vue-3.jar

Wrap Up

That completes our series on how to create your own Twitter bot running in AWS. Check out the Twitter account @vue_3 for the completed product. Also you can find all the code on GitHub.

Twitter bot with Kotlin in AWS (7 Part Series)

1) Twitter Bot - Vue 3 Updates 2) Creating an AWS Lambda Kotlin function 3 ... 5 3) Schedule our Lambda function 4) DynamoDB for our Kotlin Lambda function 5) Posting a tweet from Kotlin 6) Secrets in AWS and reading from Kotlin 7) CI/CD to AWS with GitHub Actions

Posted on Jun 21 by:

Discussion

markdown guide