.Net Core AWS Lambda architecture

How to deploy ASP.Net Core Serverless Application using CMD to AWS

Yahya Alhaj Hussein
4 min readNov 8, 2019

Serverless applications are considered the solution for many software problems where development teams want to focus on their core products instead of worrying about managing and operating servers.

If you are a .Net Core developer recently starting to develop AWS Serverless applications, using AWS Toolkit for Visual Studio would be the easiest way to create a blueprint, add your functionality and then deploy your application to AWS.

For development environments AWS Toolkit can help you deploy your application using a few mouse clicks, you just need to specify few arguments and that’s it! your application will be running on the cloud!

For production deployments, one of your options will be scripting your deployment, which can be done through:

1- Install the latest .Net Core SDK supported by AWS Lambda

Ensure that you have the latest dotnet SDK supported by AWS Lambda installed (.Net core 2.1 till the date of this post).

In order to verify that you correctly installed dotnet CLI, run the following command

dotnet --list-sdks

and verify that one of the numbers displayed matches your needed SDK.

dotnet list versions cmd

2- Install the Amazon.Lambda.Tools for the dotnet cli:

This can be achieved by running the following commands:

dotnet tool install -g Amazon.Lambda.Tools 
dotnet tool update -g Amazon.Lambda.Tools
amazon lambda tools cmd

3- Deploy your serverless application:

In order to do so, you need to navigate to your solution directory through:

cd your-solution-path

Then you run the deployment command.

dotnet lambda deploy-serverless

The above command has many parameters that you need to provide to manage the deployment process.

The information needed is basically about:

AWS Stack: a collection of AWS services needed for your application to properly work.

AWS Cloudformation: a description of the infrastructure and resources you need in your cloud environment.

AWS S3 Bucket: Bucket name that can be used to hold uploaded build output.

AWS Region: The region where you want your application to be deployed.

Credentials: which can a profile name, access key, or a session token

Full Set of available options are:

--disable-interactive                   When set to true missing required parameters will not be prompted for.
--region The region to connect to AWS services, if not set region will be detected from the environment.
--profile Profile to use to look up AWS credentials, if not set environment credentials will be used.
--profile-location Optional override to the search location for Profiles, points at a shared credentials file.
--aws-access-key-id The AWS access key id. Used when setting credentials explicitly instead of using --profile.
--aws-secret-key The AWS secret key. Used when setting credentials explicitly instead of using --profile.
--aws-session-token The AWS session token. Used when setting credentials explicitly instead of using --profile.
-pl | --project-location The location of the project, if not set the current directory will be assumed.
-cfg | --config-file Configuration file storing default values for command line arguments.
-pcfg | --persist-config-file If true the arguments used for a successful deployment are persisted to a config file.
-c | --configuration Configuration to build with, for example Release or Debug.
-f | --framework Target framework to compile, for example netcoreapp2.1.
--msbuild-parameters Additional msbuild parameters passed to the 'dotnet publish' command. Add quotes around the value if the value contains spaces.
-pac | --package Application package to use for deployment, skips building the project
-sb | --s3-bucket S3 bucket to upload the build output
-sp | --s3-prefix S3 prefix for for the build output
-t | --template Path to the CloudFormation template
-tp | --template-parameters CloudFormation template parameters. Format is <key1>=<value1>;<key2>=<value2>
-ts | --template-substitutions JSON based CloudFormation template substitutions. Format is <JSONPath>=<Substitution>;<JSONPath>=...
-cfrole | --cloudformation-role Optional role that CloudFormation assumes when creating or updated CloudFormation stack.
-sn | --stack-name CloudFormation stack name for an AWS Serverless application
-dc | --disable-capabilities Comma delimited list of capabilities to disable when creating a CloudFormation Stack.
--tags AWS tags to apply. Format is <name1>=<value1>;<name2>=<value2>
-sw | --stack-wait If true wait for the Stack to finish updating before exiting. Default is true.
-dvc | --disable-version-check Disable the .NET Core version check. Only for advanced usage.

A working example with the minimum needed options is:

dotnet lambda deploy-serverless -sn stackname -sb bucketname --region us-east-1 -t templatePath --profile default
dotnet lambda deploy-serverless cmd
dotnet lambda deploy-serverless cmd

your API link will be provided at the last of the command output.

Example:

Output Name                    Value
------------------------------ ----------------------------------
ApiURL https://u06lav76i1.execute-api.eu-west-1.amazonaws.com/Prod/

If you hit the provided URL, you should see your application up and running in the cloud!

Links:

--

--