LazyStack

Configure LazyStack Projects and DynamoDB

In this step we make some additions to the LazyStack.yaml file to support the use of DynamoDB and configure the Lambda and WebApi projects to reference the new PetStoreRepo project. Before we look at the LazyStack.yaml configuration directives in detail, here is a high-level summary of what we need to do:

  • Use ApiTagMap directive to map API endpoints to two ApiGateways.
  • Use ProjectOptions directive to configure these project options
  • Use AwsResources directive to define AWS::DynamoDB::Table resource for our stack.

When you execute "lazystack projects", the following projects are regenerated:

  • Controller projects
  • Lambda projects
  • PetStoreClientSDK project
  • PetStoreSchema project

These generated projects should not be edited as your changes would be lost.

In addition to the generated projects, portions of the WebApi project "PetStore" are updated with each execution of "lazystack projects".

Executing "lazystack projects" does not update or modify any other projects in your solution.

5.1 Update LazyStack.yaml and Generate Projects

  1. Download this LazyStack.yaml file and move it into the solution folder (LazyStackTutorial\PetStore).
  2. Edit the LazyStack.yaml file ProfileName and RegionName values if necessary.
  3. CD into the solution folder (LazyStackTutorial\PetStore) and generate projects:
    lazystack projects

    Projects and generated files are updated.

  4. Rebuild Solution.
    dotnet build
    All projects in the solution are compiled successfully.

    Note: You may see some CS8034 warnings : "Assembly with same name already loaded" - these can be ignored.

5.2 Update WebApi project (PetStore) launchSettings.json file

  1. Open the PetStore\Properties\launchSettings.json file.
  2. Add the "TABLE_NAME" environmental variable as shown below on line 25.
  3. 
    {
        "iisSettings": {
          "windowsAuthentication": false, 
          "anonymousAuthentication": true, 
          "iisExpress": {
            "applicationUrl": "http://localhost:62817",
            "sslPort": 44399
          }
        },
        "profiles": {
          "IIS Express": {
            "commandName": "IISExpress",
            "launchBrowser": true,
            "environmentVariables": {
              "ASPNETCORE_ENVIRONMENT": "Development"
            }
          },
          "PetStore": {
            "commandName": "Project",
            "launchBrowser": true,
            "applicationUrl": "https://localhost:5001;http://localhost:5000",
            "environmentVariables": {
              "ASPNETCORE_ENVIRONMENT": "Development",
              "TABLE_NAME": "PetStoreDev-DB"
            }
          }
        }
      }
    
  4. Save the file.

Step Summary

In this step we updated the LazyStack.yaml file to create a DynamoDB resource and configure the WebApi (PetStore) project and Lambdas projects to reference the PetStoreRepo project. We also added service registrations configuring the Controller projects to use the PetStoreRepo library. Finally, we inserted an environment variable "TABLE_NAME" in the WebApi project's launchSettings.json file to reference a table called "PetStoreDev-DB" in the DynamoDb resource.