LazyStack

Building the PetStore Solution

In this lesson step we will build the initial PetStore solution using the LazyStack Visual Studio Extension.

This tutorial assumes you are using the Windows Visual Studio IDE.

2.1 Create PetStore solution

  1. Configure your developer workstation with Visual Studio IDE for Windows
  2. Launch Visual Studio.
  3. Click on Create a new project. The "Create a new project" dialog appears.
  4. Type "LazyStackWebApi" into the search field. A list of project templates is presented.
  5. Double Click on the LazyStackWebApi project template. The "Configure your new project" dialog appears.
  6. Enter "PetStore" as the Project Name.
  7. Edit the Location to point to the LazyStackTutorial folder.
  8. Uncheck the 'Place solution and project in the same directory' checkbox.
  9. Click on the Create button. A solution with your PetStore WebApi project is created.
  10. Select Visual Studio menu item "Build → Rebuild Solution." The solution compiles successfully.

2.2 Add External LazyStack Projects

  1. Add External LazyStackAuth project
    1. Right Click on "Solution 'PetStore' in the Solution Explorer pane. The context menu appears."
    2. Select "Add → Exiting Project ..". The Add Exiting Project dialog appears.
    3. Select LazyStackTutorial\LazyStack\LazyStackAuth\LazyStackAuth.csproj. The project is added to your solution.
  2. Add External LazyStackDynamoDBRepo project
    1. Right Click on "Solution 'PetStore' in the Solution Explorer pane. The context menu appears."
    2. Select "Add → Exiting Project ..". The Add Exiting Project dialog appears.
    3. Select LazyStackTutorial\LazyStack\LazyStackDynamoDBRepo\LazyStackDynamoDBRepo.csproj. The project is added to your solution.

Note: In a production application you may choose to use the corresponding NuGet packages instead of using these projects directly. In this tutorial it is useful to be able to debug into these projects to understand how their features are implemented.

2.3 Download PetStore.yaml and run LazyStack Generator

  1. Click to Download PetStore.yaml file
  2. Move PetStore.yaml from your Downloads folder to the PetStore Solution root folder.
  3. Select Visual Studio menu item "Tools/LazyStack - Generate Projects". Projects and Solution Items folder are created.
    • Controllers folder
      • OrderController project
      • PetController project
    • Lambdas folder
      • Order project
      • Pet project
    • "Solution Items" folder (files are in the solution's root folder)
      • LazyStack.yaml
      • LocalApis.json
      • PetStore.yaml
      • SAM_Review.yaml
    • Stacks folder
      • Dev folder
        • serverless.template
      • Test folder
        • serverless.template
      • Prod folder
        • serverless.template
    • PetStoreClientSDK project
    • PetStoreSchema project

Note the PetStore.yaml file you dropped into the Solution's root folder is now visible in the "Solution Items" solution folder. LazyStack also created default LazyStack.yaml and default LocalApis.yaml files for you and these are also in the "Solution Items" solution folder.

2.4 Review the LazyStack.yaml file

The Generate Projects command created a default LazyStack.yaml file in your solution's root folder. The file is now visible in the "Solution Items" folder in the solution explorer. The top of your 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: ''

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

  1. Open the Solution Items\SAM_Review.yaml file.
  2. 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 -- Generate Projects.

2.6 Review serverless.template file

LazyStack Generate Projects process 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 -- Generate Projects.

Step Summary

In this lesson step we created a PetStore solution using the LazyStackWebApi project template, downloaded a OpenApi Specification called PetStore.yaml and then used the Tools → LazyStack - Generate Projects to generate projects and configuration files for our stack. We then updated the LazyStack.yaml file AWS ProfileName and RegionName.