Skip to main content

Serverless Framework(03) — Develop, deploy & troubleshoot serverless!

Serverless is the industry's buzzword these days, It doesn’t solve all the problems, but enough to become important. What exactly is server-less programming and how did we get where we are today, I have covered it here.

What this post is about?

Install Serverless

npm install -g serverless

Create an AWS IAM user for Serverless

Create a policy (Optional but recommended)

S3 - to upload & store serverless artifacts and Lambda code
EC2 - to execute Lambda in VPC
IAM - to manage policies for the Lambda IAM Role
Lambda - to manage Lambda functions
API Gateway - to manage API endpoints
CloudFormation - to create changes and update stack
CloudWatch Logs - to store Lambda execution logs
CloudWatch Events - to manage CloudWatch event triggers
Create IAM policy
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"cloudformation:*",
"s3:*",
"logs:*",
"iam:*",
"apigateway:*",
"lambda:*",
"ec2:DescribeSecurityGroups",
"ec2:DescribeSubnets",
"ec2:DescribeVpcs",
"events:*"
],
"Resource": [
"*"
]
}
]
}

Create User

Add IAM User
Attach policy to the user

Install AWS CLI

Configure CLI

aws configure 

Create a java project

serverless create \
-t aws-java-maven \
--name your-lambda-api \
--path aws-java-your-lambda-api

Update Code

Configuring the lambda

Default serverless.yml created by framework

Deploy the lambda

mvn package
serverless deploy

Test your lambda

Comments