Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

README.md

ASP.NET Core Web API Serverless Application with AWS SAM

This project shows how to use AWS SAM for an ASP.NET Core Web API project using a AWS Lambda function exposed through Amazon API Gateway.

Requirements

Deployment Instructions

  1. Create a new directory, navigate to that directory in a terminal and clone the GitHub repository:

    git clone https://github.com/aws-samples/serverless-patterns
    
  2. Change directory to the pattern directory:

    cd apigw-http-api-lambda-dotnet-sam 
    
  3. From the command line, use AWS SAM to build and deploy the AWS resources for the pattern as specified in the template.yml file:

    sam build
    sam deploy --guided
    
  4. During the prompts:

    • Enter a stack name
    • Enter the desired AWS Region
    • Allow SAM CLI to create IAM roles with the required permissions.

    Once you have run sam deploy -guided mode once and saved arguments to a configuration file (samconfig.toml), you can use sam deploy in future to use these defaults.

  5. Note the outputs from the SAM deployment process. These contain the resource names and/or ARNs which are used for testing.

How it works

==============================================

Testing

The Cloudformation stack deployment will output your API endpoint URL

CloudFormation outputs from deployed stack
-------------------------------------------------------------------------------------------------------------------------------------------------------------
Outputs                                                                                                                                                     
-------------------------------------------------------------------------------------------------------------------------------------------------------------
Key                 ApiURL                                                                                                                                  
Description         API endpoint URL for Prod environment                                                                                                   
Value               https://hr029dslcf.execute-api.ap-southeast-2.amazonaws.com/Prod/                                                                       
-------------------------------------------------------------------------------------------------------------------------------------------------------------


Successfully created/updated stack - dotnet-http-api in ap-southeast-2

You can use this endpoint to test the HTTP response

export ApiUrl=https://hr029dslcf.execute-api.ap-southeast-2.amazonaws.com/Prod/                                                            

curl $ApiUrl

Cleanup

  1. Delete the stack
    sam delete
  2. Confirm the stack has been deleted
    aws cloudformation list-stacks --query "StackSummaries[?contains(StackName,'STACK_NAME')].StackStatus"

Resources

For more .NET templates, view the .NET Lambda Tools Blueprints https://github.com/aws/aws-lambda-dotnet/tree/master/Blueprints The NuGet package Amazon.Lambda.AspNetCoreServer contains a Lambda function that is used to translate requests from API Gateway into the ASP.NET Core framework and then the responses from ASP.NET Core back to API Gateway.

For more information about how the Amazon.Lambda.AspNetCoreServer package works and how to extend its behavior view its README file in GitHub.


Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.

SPDX-License-Identifier: MIT-0