skip to Main Content

I’m trying to set up automated deployment of my .NET Core API application to an existing EB environment. I’m currently deploying manually via the AWS Toolkit (Publish to AWS) extension for Visual Studio, which works completely fine. But every time I try to set up seemingly any CI/CD pipeline, I get this exact same ERROR message after the "Added instance [i-0adf163e55a825fa9] to your environment." stage:

06:10:39 ERROR: Error occurred during build: Command hooks failed
06:10:44 ERROR: [Instance: i-0adf163e55a825fa9 ConfigSet: Infra-EmbeddedPreBuild, Hook-PostInit, Hook-PreAppDeploy, Infra-EmbeddedPostBuild, Hook-EnactAppDeploy, Hook-PostAppDeploy, Infra-WriteVersionOnStartup] Command failed on instance. Return code: 1 Output: null.
06:10:44 INFO: Command execution completed on all instances. Summary: [Successful: 0, Failed: 1].
06:10:44 ERROR: Unsuccessful command execution on instance id(s) 'i-0adf163e55a825fa9'. Aborting the operation.
06:10:44 ERROR: Failed to deploy application.
06:10:45 ERROR: Deployment failed! Current State: Version: v-638557011188113073, Health: Yellow, Health Status: Warning

I’ve tried looking at the last 100 lines of logs in the EB dashboard, as well as comb through my S3 bucket, but nothing in those logs match up with the date and time of when I receive the error messages (trying to take timezones into account too). I think I’ve gone through 12 different guides on how to setup a pipeline specifically for ASP.NET Core applications and they’ve all failed, mostly because they’re all outdated and do not match with AWS’ current interface. What am I missing?

GitHub Workflow file:

name: Deploy to Elastic Beanstalk

on:
  push:
    branches:
      - main

jobs:
  build-and-deploy:
    runs-on: windows-2019
    steps:
      - name: Checkout Code
        uses: actions/checkout@v3

      - name: Setup .NET
        uses: actions/setup-dotnet@v3
        with:
          dotnet-version: '6.0.x'

      - name: Build and Publish
        working-directory: ./API
        run: dotnet restore && dotnet publish -c Release -o publish --self-contained "true"

      - name: Create Deployment Package
        uses: thedoctor0/[email protected]
        with:
          type: 'zip'
          filename: 'API.zip'
          path: |
            APIpublish

      - name: Deploy to Elastic Beanstalk
        uses: einaregilsson/beanstalk-deploy@v22
        with:
          aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }}
          aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          application_name: AppName
          environment_name: EnvironmentName
          version_label: ${{ github.sha }}
          region: ${{ secrets.AWS_REGION }}
          deployment_package: API.zip

–EDIT:

As Delta George suggested, I tried deploying through AWS CLI. It’s worth mentioning that my API project is located in my repo as a separate folder inside of my overall repository. My project structure looks therefore as follows:

Repo  
│
└── API
│   │   API.csproj
|   |   API.sln
│   │   appsettings.json
|   |   aws-beanstalk-tools-defaults.json
|   |   web.config
|   |   etc.
│
└── Frontend project

With that in mind, I ran the following commands individually to try an deploy my API project to my EB environment using AWS CLI (v2):

dotnet publish -c Release -o ./publish
cd .publish
zip -r ../API.zip *
cd ..
aws s3 cp API.zip s3://my-s3-bucket-name/Backend/
aws elasticbeanstalk create-application-version --application-name EBAppName --version-label 1234567890 --source-bundle S3Bucket="my-s3-bucket-name",S3Key="Backend/API.zip"
aws elasticbeanstalk update-environment --environment-name EBAppNameEnv --version-label 1234567890

All commands run successfully. But checking the EB "events" output during deployment, I can eventually see the same handful of error messages show up as mentioned at the top of this post.

2

Answers


  1. Chosen as BEST ANSWER

    I managed to solve my issue, but not quite the way I originally intended.

    Until someone wants me to elaborate, I'm just gonna give a short answer here, since it seems like I was the only one in the world with this specific problem:

    After literally 80 different workflow commits and zero solutions on this issue online, I finally gave in to the evil gremlins and made the switch. I ended up creating a new EC2 application and EB environment - this time running on Linux 2023/3.1.3 instead of Windows 2019/2.15.2. After then updating my workflow, I finally got useful error messages that allowed me to make it all deploy and run successfully. Thank you Linux!

    Here is my final workflow:

    name: Deploy API to Elastic Beanstalk
     on:
       push:
         branches: ['master']
         paths: ['API/**']
    
    jobs:
      build:
        runs-on: ubuntu-latest
        defaults:
          run:
            working-directory: ./API
        steps:
          - uses: actions/checkout@v3
          - name: Setup .NET
            uses: actions/setup-dotnet@v3
            with:
              dotnet-version: '6.0.x'
    
          - name: Publish .NET project
            run: dotnet publish -c Release -o publish --self-contained false
    
          - name: Zip the contents of the publish folder
            run: cd publish && zip -r ../API.zip .
    
          - name: Deploy API.zip to EB
            uses: einaregilsson/beanstalk-deploy@v22
            with:
              aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }}
              aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
              application_name: LinuxAppName
              environment_name: LinuxEnvName
              version_label: ${{ github.sha }}
              region: ${{ secrets.AWS_REGION }}
              deployment_package: API/API.zip
    

  2. Are you sure that the access and secret keys are setup correctly and have not expired? Is the AWS_REGION correct? Does the principal represented by these keys have AWSElasticBeanstalkWebTier and AWSElasticBeanstalkManagedUpdatesCustomerRolePolicy policies attached as per this

    You mentioned AWS Toolkit extension to Visual Studio. Have you tried deploying with AWS CLI?

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search