Asrin Dayananda
Azcodez

Azcodez

Create a AWS S3 bucket with Github Actions

Create a AWS S3 bucket with Github Actions

Steps to create AWS S3 bucket using CI/CD tool GitHub Actions

Subscribe to my newsletter and never miss my upcoming articles

Below we are going to run a Github Action that creates a S3 bucket in AWS Cloud

Github workflows have AWS CLI commands built in so all you need to do it run the command See this link for more information

Create a GiHub account

Create a new repository

Setup file for workflow

  • Folder named .github
  • Folder in .github called workflows
  • Create a file called addS3BucketAWS.yml
  • See Link for more info

Add Below code to workflow file

  • This code is setup only to run when you click action in repository
# This is a basic workflow to help you get started with Actions

name: addS3BucketAWS

# Controls when the action will run. 
on:
  # Triggers the workflow on push or pull request events but only for the main branch
  # push:
  #  branches: [ main ]

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:

  # This workflow contains a single job called "build"
  build:

   # The type of runner that the job will run on
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@master

      - name: Upload to S3
        run: |
          aws s3 mb s3://<ADD BUCKET NAME MAKE SURE IT'S UNIQUE>
        env:
          AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
          AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          AWS_DEFAULT_REGION: 'eu-west-1'
  • Change this in your action

    <ADD BUCKET NAME MAKE SURE IT'S UNIQUE>
    
    • Change it to a unique name. Remember S3 names are publicly chosen. Add a random string to end of your bucket name to make sure its unique eg. I used az-test-bucket-8923yhr98uh
  • Create AWS Keys

  • Log into your AWS portal
  • Click your cloud name
  • Click 'My Security Credentials' image.png
  • Click create
  • Here you will have 2 keys which you will need to add to your repository

Add keys to your GitHub Repository

  • Click settings in your repository
  • Then secrets
  • Add repository secrets named AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY and add relevant keys from your keys created in your AWS Account

Commit and push code if you havent already

Run your action

  • In your repo
  • Click Actions
  • Select Action to run
  • Click run workflow

If successful you should have a complete success workflow like below

image.png

Hope this helped you, if this didn't please comment and I will try help you.

Remember to like, post a comment and share.

Happy Coding 🙂

Asrin 🤙

Want to start a blog on hashnode use this link so I get a free shirt. I will assist you with setup 🙂

If this helped you consider buying me a coffee 🙂

Credits

Did you find this article valuable?

Support Asrin Dayananda by becoming a sponsor. Any amount is appreciated!

See recent sponsors Learn more about Hashnode Sponsors
 
Share this