简体   繁体   中英

ASP.NET MVC AWS Elastic Beanstalk build and deploy command line

Does anyone have a link to a solid example of the scripts necessary to build an ASP.NET MVC project, package it up for awsdeploy and then deploy it to Elastic Beanstalk all via the command line? The point and click tools in VisualStudio provided by the Amazon tools are great until the team starts to grow and you need to automate with a build server.

Any help would be appreciated.

To deploy an ASP.NET project to Elastic Beanstalk using command line, you need to accomplish two steps:

  1. Build your project into a IIS deploy package
  2. Send the package using AWSDEPLOY

Step 1: Build your package

Using the msbuild.exe, pass the path of the project, a publish profile option with the package instructions and the "DeployOnBuild" option as true.

msbuild.exe "MyMvcProject.csproj" /p:Configuration=Release /p:PublishProfile=MyMvcProjectProfile /p:DeployOnBuild=True

In the publish profile file (MyMvcProjectProfile.pubxml)

  <PropertyGroup>
    <WebPublishMethod>Package</WebPublishMethod>
    <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish />
    <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
    <ExcludeApp_Data>False</ExcludeApp_Data>
    <DesktopBuildPackageLocation>$(SolutionDir)\Build\MyMvcProject.zip</DesktopBuildPackageLocation>
    <PackageAsSingleFile>true</PackageAsSingleFile>
    <DeployIisAppPath>Default Web Site/</DeployIisAppPath>
  </PropertyGroup>

Suggestion: Try use the VisualStudio Publish option to generate this file for the first time and than you can edit it.

Step 2: Send the package to Elastic Beanstalk

Pass the package that you created above, the AWS profile name with the permissions needed to make the Beanstalk Update Environment and a "config" deploy file.

awsdeploy.exe -w -r "-DDeploymentPackage=/Build/MyMvcProject.zip" "-DAWSProfileName=%username%" "beanstalk-deploy-package.txt"

The beanstalk-deploy-package.txt file is used to specify Elastic Beanstalk deploy params

Region = us-east-1
Template = ElasticBeanstalk
UploadBucket = elasticbeanstalk-us-east-1-XXXXXXXXXXXX
Application.Name = MyMvcProject
Environment.Name = production

I hope that following this you can adjust the script to your needs.

You can find more information here on AWS DOCS

Best regards

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM