Serverless C# app
Basic example of a serverless AWS application
This example lives in the pulumi/examples repository. Check out just this directory to use it:
git clone --filter=blob:none --sparse https://github.com/pulumi/examples pulumi-examplesgit -C pulumi-examples sparse-checkout set aws-py-serverless-rawcd pulumi-examples/aws-py-serverless-rawThis example deploys a complete serverless C# application using raw aws.apigateway.RestApi, aws.lambda_.Function and
aws.dynamodb.Table resources from pulumi_aws. Although this doesn’t feature any of the higher-level abstractions
from the pulumi_cloud package, it demonstrates that you can program the raw resources directly available in AWS
to accomplish all of the same things this higher-level package offers.
The deployed Lambda function is a simple C# application, highlighting the ability to manage existing application code in a Pulumi application, even if your Pulumi code is written in a different language like JavaScript or Python.
The Lambda function is a C# application using .NET Core 3.1 (a similar approach works for any other language supported by AWS Lambda).
Prerequisites#
- Install Pulumi
- Configure AWS credentials
- Install Python
- Install .NET (to build the Lambda function)
Deploying the example#
-
Create a new stack:
Terminal window pulumi stack init dev -
Build the C# application:
Terminal window dotnet publish app -
Set the AWS region to deploy into:
Terminal window pulumi config set aws:region us-east-2 -
Optionally, set AWS Lambda provisioned concurrency:
Terminal window pulumi config set provisionedConcurrency 1 -
Install dependencies:
Terminal window python3 -m venv venvsource venv/bin/activatepip install -r requirements.txt -
Run
pulumi upto preview and deploy changes:Terminal window pulumi upPreviewing update (dev):...Updating (dev):...Resources:+ 10 createdDuration: 1m 20s -
Check the deployed endpoint:
Terminal window curl $(pulumi stack output endpoint)/hello{"Path":"/hello","Count":0} -
View the logs:
Terminal window pulumi logs -f2018-03-21T18:24:52.670-07:00[ mylambda-d719650] START RequestId: d1e95652-2d6f-11e8-93f6-2921c8ae65e7 Version: $LATEST2018-03-21T18:24:56.171-07:00[ mylambda-d719650] Getting count for '/hello'2018-03-21T18:25:01.327-07:00[ mylambda-d719650] Got count 0 for '/hello'2018-03-21T18:25:02.267-07:00[ mylambda-d719650] END RequestId: d1e95652-2d6f-11e8-93f6-2921c8ae65e72018-03-21T18:25:02.267-07:00[ mylambda-d719650] REPORT RequestId: d1e95652-2d6f-11e8-93f6-2921c8ae65e7 Duration: 9540.93 ms Billed Duration: 9600 ms Memory Size: 128 MB Max Memory Used: 37 MB
Cleaning up#
Once you’re finished experimenting, destroy your stack and remove it to avoid incurring any additional cost:
pulumi destroypulumi stack rm