AWS Steps to setup Serverless & Lambda

by Admin 11. February 2017 08:04

AWS Command Line Interface

https://aws.amazon.com/cli/

AWS Toolkit for Visual Studio

https://aws.amazon.com/visualstudio/

Install NodeJS & Git Bash

install node js tools for visual studio

https://www.visualstudio.com/vs/node-js/

Install serverless globally

The commands are here https://serverless.com/

npm install serverless -g

Create an AWS Lambda function 

In Node.js

serverless create --template aws-nodejs

 In C#

 serverless create --template aws-csharp -p serverless-Sample1 -n LambdaService

Now open the project in Visual Studio

Add yaml Syntax Highlighting Pack nuget package

https://marketplace.visualstudio.com/items?itemName=MadsKristensen.MarkdownEditor

Next

Modfiy the serverless.yml file to use the respective access credentails as below

provider:

  name: aws

  runtime: dotnetcore1.0

  stage: dev

  region: ${self:custom.configuration.providerRegion}

  credentials:

accessKeyId: ${self:custom.configuration.accessKeyId}

secretAccessKey: ${self:custom.configuration.secretAccessKey}

Note:

In the above I have referred the credentials and the region from an external config.yml file.

Here are the steps to do add the external file

Create a new config.yml file

Paste the below config stuff

#configuration

 #AWS config

providerRegion: eu-west-2 (you need to set yours here)

awsAccessKey:PASTE_YOUR_ACCESS_KEY_HERE

awsSecretKey:PASTE_YOUR_SECRET_KEY_HERE

accountId:PASTE_YOUR_ACCOUNT_ID_HERE

Going back to servreless.yml file

You add / modify default settings

eg: I have added to exclude teh git stuff as part of the deployment package

# you can add packaging information here

package:

  artifact: bin/release/netcoreapp1.0/publish/deploy-package.zip

  exclude:

  - .git/**

Now right click build.ps1 file and open with powershell

Now run this command 

./build.ps1

Now the buid will be completed an places a folder in the below location and created a package.zip file to deploy

C:\VENKAT\Learning\AWS\Dev\serverless-Sample1\bin\release\netcoreapp1.0\publish

serverless-Sample1 is my application name

Now go to the gitbash "C:\VENKAT\Learning\AWS\Dev\Serverless-Sample1>" location

Now deploy the code on the serve rusing the following command

sls deploy

The above deploy happends from the default location as below

C:\VENKAT\Learning\AWS\Dev\Serverless\bin\release\netcoreapp1.0\publish

The code is successfully deployed on the server now.

Now go to the AWS Lamda 

https://eu-west-2.console.aws.amazon.com/console/home?region=eu-west-2#

Search for Lamda

You should be able to view the lambda function we created

You can test by clicking the Test button.

 

Now its time to deploy the Lambda function on to the API Gateway

Go to the API gateway location by searching

https://eu-west-2.console.aws.amazon.com/apigateway/home?region=eu-west-2#/apis

 

Here you should be able to view the function which needs to be deployed on to API gateway

Now configure Method Execution  /users/create - GET - Method Request

You can add the 3 query params key1, key2 & key3

Now add a method HTTP Status: 200

Set the Use Lambda Proxy integration to False (UnCheck)

 

Now deploy the site from the Actions dropdown.

Test the function here 

 

Now 

https://eu-west-2.console.aws.amazon.com/apigateway/home?region=eu-west-2#/apis/ayd0i0b484/resources/g21af8/methods/GET

Make sure you deploy

https://ayd0i0b484.execute-api.eu-west-2.amazonaws.com/dev/users/create?request=test

 

Deploy to live AWS account

serverless deploy

UFunction deployed!

http://api.amazon.com/users/update

 

Janisha-GBRL01483M17.pdf (566.60 kb)

Vijay-GBRL01481M17.pdf (564.19 kb)

Tags:

Comments are closed

TextBox

Tag cloud

    RecentPosts