Posting a small utility which you can include in yours DotNetCore AWS development steps to enable CORS on AWS API Gateway resources.
For DotNetCore lambda development
The serverless.template file is where you define all your resources for the API Gateway. However there is no way to create mock API Gateway requests which is something most of us need to create the OPTIONS method while enabling CORS.
The EnableCORS.dll program allows you to enable OPTIONS method on your API Gateway resources by listing all the required resource paths in a text file and running the dll using .NET Core 1.0.
Sample file contents:
#How to create entires #path=/roles #allowed-origins=* or comma-separated list of addresses #allowed-headers=comma-separated list of headers #allowed-methods=get,options or just * path=/posts allowed-origins=* allowed-headers=Content-Type,x-requested-with,Access-Control-Allow-Headers,Access-Control-Allow-Origin,Access-Control-Allow-Methods allowed-methods=get,options path=/categories allowed-origins=mydomain.com,myhost.com allowed-headers=Content-Type,x-requested-with,Access-Control-Allow-Headers,Access-Control-Allow-Origin,Access-Control-Allow-Methods allowed-methods=*
In the above file I am saying that I want to enable CORS for the /posts and /categories paths in AW API Gateway. Once the paths are define I only need to run the following command:
DotNet EnableCORS -accesskey BAABAABLACKSHEEPFZ5A -secretkey MYSUPERSUPERSECRETKEY -region us-east-1 -apiid myapi5idv5 c:\\deployment\\cors.txt
Hope this post was useful.