Skip to content

Latest commit

 

History

History
32 lines (18 loc) · 1.69 KB

File metadata and controls

32 lines (18 loc) · 1.69 KB

Custom Configuration Example

It is sometimes useful to add multiple configuration sources. This example illustrates the use of a custom config factory to achieve that.

Files

Steps to Recreate

  1. Create a new netcoreapp3.1 and add the following packages:

    • Lambdajection
  2. Create a ConfigFactory that enables file-based configuration. Set the ConfigFactory argument in the Lambda Handler attribute to point to your config factory's type.

  3. Create a Config / Options class that will be used to hold your configuration items. Inject this class into your handler and read values from it inside the Handle method.

  4. Add a Startup Class and configure any services that will be injected into your Lambda Handler in here.

  5. Create a CloudFormation template for your Lambda.

    • Note that we are using the serverless transform in the example, however using the transform is optional.

How it Works

  1. During a build, the generator will use your config factory in place of the default one. The type of this class is added as a generic argument to the Lambda Host.
  2. When the lambda is run, the Lambda Host Builder will create a new instance of your config factory and create a configuration instance using that factory. That config instance will then be added to the service collection / provider passed to the lambda host as well as your startup class.