In this lesson step we will build the initial PetStore solution using the .NET CLI LazyStack Tool.
mkdir PetStore
cd PetStore
dotnet new sln
dotnet new webapi -o PetStore
Windows: dotnet sln add PetStore\PetStore.csproj
MacOS/Linux: dotnet sln add PetStore/PetStore.csproj
You now have a PetStore Solution with a PetStore WebApi project in it.dotnet build
The solution compiles successfully.using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace PetStore
{
public partial class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
ConfigureSvcs(services);
services.AddControllers();
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo { Title = "PetStoreAPI", Version = "v1" });
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "PetStore V1");
});
app.Run(async (context) => await Task.Run(() => context.Response.Redirect("/swagger")));
}
}
}
dotnet build
The solution compiles successfully.dotnet sln add ..\LazyStack\LazyStackAuth\LazyStackAuth.csproj
dotnet sln add ..\LazyStack\LazyStackDynamoDBRepo\LazyStackDynamoDBRepo.csproj
lazystack projects
Multiple projects and configuration files are created.
The "lazystack projects" command created a default LazyStack.yaml file in your solution's root folder. The top of the LazyStack.yaml file should look like this:
LazyStackDirectivesVersion: 1.1.0
Stacks:
Dev:
ProfileName: default
RegionName: us-east-1
StackName: PetStoreDev
Stage: Dev
UriCodeTarget: Debug/net6.0
Test:
Stage: Test
UriCodeTarget: Release/net6.0
Prod:
Stage: Prod
UriCodeTarget: Release/net6.0
ProjectOptions:
NugetPackageVersions:
Amazon.Lambda.AspNetCoreServer: 7.2.0
AWSSDK.Extensions.NETCore.Setup: 3.7.2
JsonSubTypes: 1.9.0
LazyStackAuth: 3.0.0
Newtonsoft.Json: 13.0.1
Swashbuckle.AspNetCore: 6.4.0
System.ComponentModel.Annotations: 5.0.0
System.IdentityModel.Tokens.Jwt: 6.22.0
ClientSDKProjects:
PackageReferences:
LazyStackAuth: ''
System.ComponentModel.Annotations: ''
JsonSubTypes: ''
Newtonsoft.Json: ''
SchemaProjects:
PackageReferences:
Newtonsoft.Json: ''
LambdaProjects:
Runtime: dotnet6
PackageReferences:
AWSSDK.Extensions.NETCore.Setup: ''
Amazon.Lambda.AspNetCoreServer: ''
WebApiProjects:
PackageReferences:
AWSSDK.Extensions.NETCore.Setup: ''
Swashbuckle.AspNetCore: ''
ControllerProjects:
PackageReferences:
System.IdentityModel.Tokens.Jwt: ''
The SAM_Review.yaml file was generated in the solution folder. This file contains the stack configuration without stack environment specific content inserted. Stack environments might include Dev, Test and Prod. Fully constituted templates are placed in the serverless.template files placed in the stack environment folder. For instance, the Stacks\Dev\serverless.template file is the template you will later use to publish the PetStoreDev stack to AWS.
You never edit the SAM_Review.yaml file directly.
The SAM_Review.yaml file will be updated with new content as we add and configure AWS stack resources during the tutorial. This file is regenerated each time you execute "lazystack projects".
The "lazystack projects" commands generates one serverless.template file for each environment. In this case, we have one Stacks Environment called "Dev" so a serverless.template file is generated in the Stacks\Dev folder.
You want to review the SAM template we will later publish to AWS. You never edit this file directly.
The serverless.template file will be updated with new content as we add and configure AWS stack resources during the tutorial. This file is regenerated each time you execute "lazystack projects".
In this lesson step we created a PetStore solution using the WebApi project template, downloaded a OpenApi Specification called PetStore.yaml and then used the .NET CLI Tool "lazystack projects" to generate projects and configuration files for our stack. We then updated the LazyStack.yaml file AWS ProfileName and RegionName.