LazyStack

Building the PetStoreCLI Solution

In this lesson step we will build the initial PetStore solution using the .NET CLI LazyStack Tool.

1.1 Create PetStoreCLI solution

  1. Configure your developer workstation with the LazyStack .NET CLI Tool
  2. Open a Command Prompt.
  3. Use .NET CLI to create a solution with a WebApi project in it.
    mkdir LazyStackTutorial
    cd LazyStackTutorial
    mkdir PetStoreCLI
    cd PetStoreCLI
    dotnet new sln
    dotnet new webapi -o PetStoreCLI
    Windows:
    dotnet sln add PetStoreCLI\PetStoreCLI.csproj
    MacOS/Linux:
    dotnet sln add PetStoreCLI/PetStoreCLI.csproj
    You now have a PetStoreCLI Solution with a PetStoreCLI WebApi project in it.
  4. Build the solution.
    > dotnet build
    The solution compiles successfully.
  5. Download ConfigureSvcs.cs and place it into the PetStoreCLI project folder.
  6. Edit the WebApi project to use ConfigureSvcs.cs.
      Edit PetStoreCLI\Startup.cs Note line numbers 4 and 19
      ...
      namespace PetStoreCLI
      {
          public partial class Startup // NOTE addition of partial 
          {
      
              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); // NOTE insertion of call to ConfigureSvcs method
                  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")));
      
              }
          }
      }
  7. Remove the PetStoreCLI\Controllers\WeatherForecastController.cs file.
  8. Remove the PetStoreCLI\WeatherForecast.cs file.
  9. CD into the solution folder (LazyStackTutorial\PetStoreCLI). Rebuild the solution.
    dotnet build
    The solution compiles successfully.

1.2 Download PetStoreCLI.yaml and run LazyStack Generator

  1. Download the PetStoreCLI.yaml file and place it into the PetStoreCLI solution folder
  2. CD into the solution folder (LazyStackTutorial\PetStoreCLI) and run the LazyStack generator:
    lazystack projects
    Multiple projects and configuration files are created.
    • Controllers folder
      • OrderController project
      • OrderSecureController project
      • PetController project
      • PetSecureController project
    • Lambdas folder
      • Order project
      • OrderSecure project
      • Pet project
      • PetSecure project
    • Solution items (placed in solution's root folder)
      • LazyStack.yaml
      • LocalApis.json
      • PetStore.yaml
      • SAM_Review.yaml
    • Stacks folder
      • Dev folder
        • serverless.template
    • PetStoreCLIClientSDK project
    • PetStoreCLISchema project

1.3 Edit the LazyStack.yaml file

The "lazystack projects" command created a default LazyStack.yaml file in your solution's root folder. You may need to update it with your AWS profile and AWS region. Your initial LazyStack.yaml file should look like this:

# LazyStack Version 1.0.0
Stacks:
    Dev:
    ProfileName: default
    RegionName: us-east-1
    StackName: PetStoreCLIDev 
    Stage: Dev
    UriCodeTarget: Debug/netcoreapp3.1
    ...
  1. Open the LazyStack.yaml file.
  2. Edit the ProfileName.

    You may modify the ProfileName if you are not using the profile "default" - Note: the profile "default" is created by the AWS CLI install unless you specify some other named profile.

  3. Edit the RegionName if you are not using the "us-east-1" region.
  4. Save the file.

1.4 Review the SAM_Review.yaml

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.

  • Open the SAM_Review.yaml file.
  • Review contents. No need to understand all this content now.
  • 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".

    1.5 Review serverless.template file

    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.

    1. Open the Stacks\Dev\serverless.template file.
    2. Review contents. No need to understand all this content now.

    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".

    Step Summary

    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.