DEV Community

Cover image for Automatic Deployment .NET Web API to AWS Elastic Beanstalk using GitHub Action

Automatic Deployment .NET Web API to AWS Elastic Beanstalk using GitHub Action

Hello everyone!

I want to share how to automatically deploy .NET Web API to AWS Elastic Beanstalk. We will use GitHub Action as a deployment tool.

Please take a look at my strategy for the deployment process.

  1. Publish the .NET Application
  2. Zip the published .NET Application
  3. Set up the EB (Elastic Beanstalk) CLI
  4. Deploy with eb deploy --staged

Infrastructure Provisioning

Thanks to SAGAR/SHANKY for providing a great tutorial to provision AWS Elastic Beanstalk using Terraform. Please take a look into at their article. If you are curious my adoption, please take a look here.

If you are unsure how to use the Terraform, no worries. I would like to explain Terraform and AWS Elastic Beanstalk in the next article. You may provision AWS Elastic Beanstalk manually.

Setting up GitHub Action

As mentioned at the beginning of my strategy, you may need to find these detailed steps of the Pipeline. You may need to check in the repository.

name: Deploy .NET
on:
  push:
    branches:
    - main
jobs:
  build_deploy:
    name: Build & Deploy
    runs-on: ubuntu-latest
    steps:
    - name: Checkout source code
      uses: actions/checkout@v2
    - uses: actions/setup-dotnet@v3
      with:
        dotnet-version: '6.0.x'
    - name: Publish
      run: dotnet publish WebApi -o site
    - name: Generate deployment package
      run: cd site; zip -r ../deploy.zip . -x '*.git*'; cd ..
    - name: Upload .NET to artifact
      uses: actions/upload-artifact@v3
      with:
        name: dotnet-zip
        path: deploy.zip
    - name: Setup EB CLI
      run: |
        python --version
        pip --version
        pip install awsebcli --upgrade --user
        eb --version
    - name: Configure AWS credentials
      uses: aws-actions/configure-aws-credentials@v2 # More information on this action can be found below in the 'AWS Credentials' section
      with:
        role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
        role-session-name: ${{ secrets.AWS_ROLE_SESSION_NAME }}
        aws-region: 'ap-southeast-1'
    - name: Deploy to EB
      run: eb deploy dotnet-env-dev --staged
Enter fullscreen mode Exit fullscreen mode

Additionally, I added a step of uploading to the artifact to archive the published result.


Room of improvement:

  • Using multiple stages/jobs
  • Setting tools using Docker container, provide the tools of Elastic Beanstalk CLI using Docker, and set that as the action.

References & Artifacts

Repository

GitHub logo bervProject / tf-beanstalk-dotnet-6

Terraform Beanstalk .NET 6

Deployed Version

Deployed Version

Thank you

Thank you for reading my short article. Feel free to give feedback in the comment section. Have a great day!

Thank you GIF

Top comments (3)

Collapse
 
onlinemsr profile image
Raja MSR

This is a very informative and useful post. I appreciate how you explained the steps to deploy a .NET Web API to AWS Elastic Beanstalk using GitHub Action. Thank you for sharing your knowledge and experience with the community.

When deploying code using GitHub Actions, where node details will be maintained?

Collapse
 
berviantoleo profile image
Bervianto Leo Pratama

Currently, I'm using a method similar to uploading the source code files in the AWS Console. The deployment process from the source code to the target (for example, EC2) will be handled by AWS Elastic Beanstalk.

The node details could be maintained by AWS Elastic Beanstalk.

CMIIW (Correct Me If I'm Wrong).

Collapse
 
onlinemsr profile image
Raja MSR

Thank you!

I will explore further on this.