ASP.NET Core app deploy to AWS Beanstalk using GitHub Actions - amazon-web-services

I am trying to build a CD pipeline using the GitHub Actions and AWS Beanstalk (Linux) for my ASP.NET Core 3.1 app.
I have configured the YML file as follows:
- name: dotnet Build
run: dotnet build src/SLNNAME.sln -c Release --no-restore
- name: dotnet Publish
run: |
dotnet publish src/SLNNAME.Server/SLNAME.Server.Web/SLNNAME.Server.Web.csproj -c Release -o staging_SLNNAME_server -r linux-x64
- name: Build deployment package
run: zip -r staging-server-deploy.zip staging_SLNNAME_server
..
- name: Deploy to AWS Beanstalk
uses: einaregilsson/beanstalk-deploy#v10
with:
aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
region: ${{ secrets.AWS_REGION }}
application_name: SLNNAME-staging-app-web
environment_name: SLNNAME-staging-server
version_label: "staging-app-web-${{ steps.format-time.outputs.replaced }}"
deployment_package: staging-server-deploy.zip
But an error occurs during the deployment to AWS. In particular, looking at the Beanstalk logs I can read the following error:
[ERROR] An error occurred during execution of command [app-deploy] - [CheckProcfileForDotNetCoreApplication]. Stop running the command. Error: error stat /var/app/staging/staging_SLNNAME_server/SLNNAME.dll: no such file or directory with file /var/app/staging/staging_SLNNAME_server/SLNNAME.dll
Basically, I think it is looking for a DLL with the solution name instead of the project name - SLNName.Server.Web. I wonder yet where it is picking up the solution name, since it is not part of the zip file.
I gave a try with the --self-contained flag as well, but the error is exactly the same.
I have this error even if I try to publish the solution using the AWS toolking Visual Studio extension.
The only way I have found to fix this is to change the project output DLL name to match the solution one, but it doesn't make any sense to me - I might have more problems in future.
Thanks

Warning: This is a workaround, not a solution!
On the project that's failing to deploy, change the "Assembly name" in Project Properties / Application tab, to the name of the DLL it's missing (typically the solution name or the first period-separated part of the namespace).
i.e. "SLNNAME"
Then, redeploy your beanstalk app and it should work.

I have opened a ticket on AWS platform and this issue has been stated as a bug by the support team.
They replied to me with:
I reached out to internal team and informed the team regarding the bug. [...] I have added your voice for this request I raised with internal team to add more weightage on the issue. Currently, I am unable to provide you with ETA [...] you can certainly be assured that the internal team is looking into this issue and fix it as quickly as possible
Hoping they will fix this soon as possible

Today I received an email from AWS support saying the issue has been fixed.
I have tried it and actually it works!
Please be sure to use Linux 2/2.0.1 as platform

Related

Azure DevOps CICD build pipeline fails with error: specified command or file was not found

I have a CICD build pipeline in Azure Devops for building a .NET Core AWS API Gateway Serverless application. The Pipeline is using hosted Windows 2019. The step that fails is:
steps:
- task: AmazonWebServices.aws-vsts-tools.LambdaNETCoreDeploy.LambdaNETCoreDeploy#1
displayName: 'Build solution and generate CloudFormation template. '
inputs:
awsCredentials: 'AWS - Development (Infrastructure)'
regionName: 'ap-southeast-2'
command: deployServerless
packageOnly: true
packageOutputFile: '$(Build.ArtifactStagingDirectory)\serverless-output.yaml'
lambdaProjectPath: testapi/LCSApi.csproj
s3Bucket: 'api-dev-xxxxxxxx-s3'
s3Prefix: 'azure_devops_builds/lcs/'
additionalArgs: '-template serverless.template '
All I get from the error is the following:
Beginning Serverless Deployment
Performing package-only build of serverless application, output template will be placed in D:\a\1\a\serverless-output.yaml
"C:\Program Files\dotnet\dotnet.exe" lambda package-ci -ot D:\a\1\a\serverless-output.yaml --region ap-southeast-2 --s3-bucket api-dev-xxxxxx-s3 --s3-prefix azure_devops_builds/lcs/ --disable-interactive true -template serverless.template
Could not execute because the specified command or file was not found.
Possible reasons for this include:
* You misspelled a built-in dotnet command.
* You intended to execute a .NET Core program, but dotnet-lambda does not exist.
* You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.
##[error]Error: The process 'C:\Program Files\dotnet\dotnet.exe' failed with exit code 1
Finishing: Build solution and generate CloudFormation template.
However, if I re-run the pipeline straight after this failure, it works fine. Additionally, it does not always fail with this error. Around 70-80% of the time the pipeline works fine. What could this be and how can i address it?
Can you try adding this before your step:
powershell: |
dotnet tool install --global Amazon.Lambda.Tools --version 3.1.1
dotnet tool update -g Amazon.Lambda.Tools

Azure DevOps YAML self hosted agent pipeline build is stuck at locating self-agent

Action: I tried to configure and run a simple c++ azure pipeline on a self-hosted windows computer. I'm pretty new to all this. I ran the script below.
Expected: to see build task, display task and clean task. to see hello word.
Result: Error, script can't find my build agent.
##[warning]An image label with the label Weltgeist does not exist.
,##[error]The remote provider was unable to process the request.
Pool: Azure Pipelines
Image: Weltgeist
Started: Today at 10:16 p.m.
Duration: 14m 23s
Info & Test:
My self-hosted agent name is Weltgeist and it's part of the
default agent pools.it's a windows computer, with all g++, mingw and
other related tools on it.
I tried my build task locally with no problem.
I tried my build task using azure 'ubuntu-latest' agent with no
problem.
I created the self-hosted agent following these specification.
I'm the owner of the azure repo.
https://learn.microsoft.com/en-us/azure/devops/pipelines/agents/v2-windows?view=azure-devops
How do I configure correctly the pool ymal parameter for self-hosted agent ?
Do i have addition steps to do server side? or on azure repo configs?
Any other idea of what went wrong?
# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml
trigger:
- master
pool:
vmImage: 'Weltgeist' #Testing with self-hosted agent
steps:
- script: |
mkdir ./build
g++ -g ./src/hello-world.cpp -o ./build/hello-world.exe
displayName: 'Run a build script'
- script: |
./build/hello-world.exe
displayName: 'Run Display task'
- script: |
rm -r build
displayName: 'Clean task'
(UPDATE)
Solution:
Thx, after updating it as stated in a answer below and reading a bit more pool ymal definition it works. Note, I modified a couple of other lines to make it work on my environment.
trigger:
- master
pool:
name: Default
demands:
- agent.name -equals Weltgeist
steps:
- script: |
mkdir build
g++ -o ./build/hello-world.exe ./src/hello-world.cpp
displayName: 'Run a build script'
- script: |
cd build
hello-world.exe
cd ..
displayName: 'Run Display task'
- script: |
rm -r build
displayName: 'Clean task'
I was confused by the Default because there was already a pipeline named Default in the organization.
Expanding on the answers provided here.
pool:
name: NameOfYourPool
demands:
- agent.name -equals NameOfYourAgent
Here is screen you'll find that information in DevOps.
Since you are using the self-hosted agent, you could use the following format:
pool:
name: Default
demands:
- agent.name -equals Weltgeist
Then it should work as expected.
You could refer to the doc about POOL Definition in Yaml.
I had faced the same issue and replacing vmImage under pool with "name" worked for me. PFB,
trigger:
master
pool:
name: 'Weltgeist' #Testing with self-hosted agent
Also be aware that if your agent only appears in the "Azure Pipelines" pool and not in any of the other pools then the agent may have been configured to be an "Environment" resource, and can't be used as part of the build step.
I spent ages trying to use a self-hosted VM for a build step, thinking that the correct way to reference the VM was by creating a VM resource from the Pipelines > Enviroments area:
The agent would be properly created and visible in the "Azure Pipelines" pool, but wouldn't be available in any of the other pools, which then meant it couldn't be referenced in the yaml used for setting the server used for builds.
I was able to resolve the issue, by de-registering the agent on my self-hosted VM with .\config.cmd remove and running ./config without the --environment --environmentname "<name>" that was provided within the registration script mentioned above (shown in the "Add reseouce" screenshot)
Oddly, the registration script is a much quicker way to register an Agent than the "New agent" form shown in Agent Pools:
The necessary files are pulled to the server (without having to download one first) and a PAT with a 3-hour lifetime is auto-generated.

AWS deployment "Unable to remove top level folder"

I have installed the Bitbucket addon to deploy with AWS CodeDeploy but for an unknown reason, I get this error "Unable to remove top level folder" when I try to deploy from the bitbucket view.
This is my appspec.yml
version: 0.0
os: linux
files:
- source: /
destination: /var/www/citytwig
hooks:
AfterInstall:
- location: scripts/configure.sh
timeout: 300
runas: root
I have already deployed other bitbucket repositories successfully, I'm wondering why this one doesn't work.
Aws codedeploy tries to rollback previous deployment before it applies a new one. It can happen that you have deleted some files manually on the instance and now rollback script is failing.
Solution
Delete rollback scripts of codedeploy-agent on the instance.
if you are using ubuntu, ssh into instance and go to the directory
cd /opt/codedeploy-agent/deployment-root/deployment-instructions/
and look for a file that ends with -cleanup
delete this file.
Now try you deployment again.
Check out documentation, or read it in Rollback and Redeployment Workflow section of pdf
Depending on the rollback script the Deployment may fail with different messages, for me it was Directory not empty # dir_s_rmdir
But it always fails on Install Event.
After a long searching, I realized that a file had Russian characters on his filename.
It seems that the Bitbucket CodeDeploy Addon have issues with this kind of characters.
I had got the exact error, but in my case, it was a typo in the file name appspec.yml

How do specify an environment name for elastic bean stalk?

I am trying to deploy to elastic beanstalk using the cli.
The command I run is
eb create --modules ebtargets/goapi -v
I get the following error
WARNING: You have uncommitted changes.
INFO: Getting version label from git with git-describe
INFO: Uploading archive to s3 location: goapi/app-d4ec2-160630_135740.json
Uploading goapi/app-d4ec2-160630_135740.json to S3. This may take a while.
Upload Complete.
INFO: Creating AppVersion app-d4ec2-160630_135740
--- Waiting for application versions to be pre-processed ---
Finished processing application version app-d4ec2-160630_135740
--- Creating modules ---
ERROR: ServiceError - ApplicationVersion app-d4ec2-160630_135740 must specify an environment name in env.yaml
I have the key EnvironmentName in my env.yaml file. Any help on this?
I had a similar problem and I noticed you have to check your env.yaml into version control otherwise it won't be used:
git add env.yaml
git commit -m "add elastic beanstalk environment config"
Check that you have an .elasticbeanstalk folder into your ebtargets/goapi
If necessary, use eb init --modules ebtargets/goapi.
More information here

AWS Elastic Beanstalk - ERROR: No Application Version named 'v0_9_2-76-gf5a4' found

I'm trying to deploy my code to AWS Beanstalk and get this error. I researched that it could be that the number of versions is more than 500, so I deleted a lot of versions. But, I still get this error.
eb deploy
ERROR: No Application Version named 'v0_9_2-76-gf5a4' found.
I also tried
git aws.push
Error: Failed to create the AWS Elastic Beanstalk application version
Edit:
Trying with eb deploy --debug I now get:
Instance: i-2ad238d5 Module: AWSEBAutoScalingGroup ConfigSet: null Command failed on instance. Return code: 1 Output: Error occurred during build: Command hooks failed . Script /opt/elasticbeanstalk/hooks/appdeploy/pre/10_bundle_install.sh failed with returncode 18
ebcli.objects.exceptions.ServiceError: Update environment operation is
complete, but with errors. For more information, see troubleshooting
documentation.
Did you update the file .elasticbeanstalk/config.yml ? It may have a wrong setup.
Make a backup of .elasticbeanstalk/ folder and remove it
Execute eb create
Select the same region you deployed it before. You can check the region on .elasticbeanstalk/config.yml backup
A list with the environments will appear, select the right one
Deploy now
Remove the .elasticbeanstalk/config.yml backup
Check for the .elasticbeanstalk/config.yml file
environment: CORRECT_ENV_NAME
global:
application_name: CORRECT_APP_NAME
In my case, I was doing eb deploy X where X was an environment for a different project.
When I had the error
InvalidParameterValueError: No Application Version named 'app-9f5c-180927_071528' found.
I fixed this by specifying the label I wanted to push up.
eb deploy XXX-env -l XXX.0.0.1
The -l flag is documented AWS EB Deploy Docs
most likely, the deploy is trying an incorrect Elasticbeanstalk Application. it could be because you renamed the application in the AWS console.
so double check you're pointing to the correct elasticbeanstalk Environment and Application. it could be picking out default values from your .elasticbeanstalk/config.yml file.