DEV Community

Ashutosh Singh for AWS Community Builders

Posted on

4

GitHub Action with EC2 and SSH

Sometimes we are stuck with a use case which is not very efficient
but are essentials for the pipeline or CI/CD there are so many reasons why this could arise, cost, time & effort, it's not production we can do whatever we want!!

Here's How

you can connect any virtual machine whether it's deployed on AWS, Azure or GCP they all have something in common,
SSH either password or .pem file this method will work just fine.
I know this is not what we as a DevOps Guy prefer but you have to make something out of this situation you're stuck, right !!

For this, I'm gonna use GitHub Action, SSH DEPLOY action and AWS(I mean why not).

STEP I

Setup your authentication for my case ACCESS KEY & SECRET KEY
Add them to GitHub Secret

GitHub Secret
Password is the .pem key for the instances we gonna deploy the application.

NOTICE: After this setup the HOST, USERNAME, and PORT(if you have changed ur default SSH port) in the variable section

Here's the GitHub Action



name: Deployment to server
on:
    workflow_run:
        workflows: ["Docker Image CI"]
        types: 
            - completed
jobs:

  Deploy:
    name: Deploy
    runs-on: ubuntu-latest
    if: github.event.workflow_run.conclusion == 'success'

    steps:
        - uses: easingthemes/ssh-deploy@v5.0.0
          name: Deploy over SSH
          with:
            SSH_PRIVATE_KEY: ${{ secrets.PASSWORD }}
            REMOTE_HOST: ${{ vars.HOST }}
            REMOTE_USER: ${{ vars.USERNAME }}
            SCRIPT_AFTER: |
                ./script
                // PUT THE COMMANDS HERE



Enter fullscreen mode Exit fullscreen mode

And Voila!! here you go I like this GitHub action due to its simplicity and ease of use with private keys.
Deployment Done

Thank you for reading.
Feel free to reach out for any suggestions.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

Create a simple OTP system with AWS Serverless cover image

Create a simple OTP system with AWS Serverless

Implement a One Time Password (OTP) system with AWS Serverless services including Lambda, API Gateway, DynamoDB, Simple Email Service (SES), and Amplify Web Hosting using VueJS for the frontend.

Read full post

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay