0% found this document useful (0 votes)
16 views2 pages

Serverless Function in AWS

This document outlines the process of orchestrating serverless functions using AWS Step Functions and AWS Lambda. It details the steps to create two Lambda functions, set up a Step Function workflow, grant necessary permissions, and execute the workflow. Additionally, it includes optional steps for monitoring execution logs in AWS CloudWatch.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views2 pages

Serverless Function in AWS

This document outlines the process of orchestrating serverless functions using AWS Step Functions and AWS Lambda. It details the steps to create two Lambda functions, set up a Step Function workflow, grant necessary permissions, and execute the workflow. Additionally, it includes optional steps for monitoring execution logs in AWS CloudWatch.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Program No: 9

Orchestrating Serverless Functions with AWS Step Functions

AWS Step Functions allows you to coordinate AWS Lambda functions and other AWS
services into serverless workflows without provisioning servers.

Step 1: Set Up AWS Lambda Functions

1️⃣ Create First Lambda Function (StartFunction)

1. Go to the AWS Lambda Console → Click “Create Function”.


2. Choose “Author from scratch”.
3. Function Name: StartFunction
4. Runtime: Choose Python 3.9 or Node.js 18.x.
5. Click "Create Function".
6. In the Code section, replace the default code with:

import json

def lambda_handler(event, context):


return {"message": "Step Function Started", "status": "Success"}

7. Click Deploy.

2️⃣ Create Second Lambda Function (ProcessFunction)

1. Repeat the steps above but name the function ProcessFunction.


2. Replace the code with:

import json

def lambda_handler(event, context):


return {"message": "Processing Complete", "status": "Success"}

3. Click Deploy.

Step 2: Create an AWS Step Function Workflow

1. Go to AWS Step Functions Console → Click "Create state machine".


2. Choose "Author with Code" → Copy & Paste this JSON:

{
"Comment": "A simple AWS Step Functions state machine",
"StartAt": "StartFunction",
"States": {
"StartFunction": {
"Type": "Task",
"Resource":
"arn:aws:lambda:REGION:ACCOUNT_ID:function:StartFunction",
"Next": "ProcessFunction"
},
"ProcessFunction": {
"Type": "Task",
"Resource":
"arn:aws:lambda:REGION:ACCOUNT_ID:function:ProcessFunction",
"End": true
}
}
}

Replace REGION & ACCOUNT_ID with your AWS details.


Example: "arn:aws:lambda:us-east-
1:123456789012:function:StartFunction"

3. Click Next → Name it ServerlessWorkflow.


4. Choose Standard Workflow (Free Tier Eligible).
5. Click Create State Machine.

Step 3: Grant Permissions for Step Functions to Invoke Lambda

1. Go to the IAM Console → Select the Step Functions execution role.


2. Click "Attach Policies" → Add:
o AWSLambdaRole
o AWSLambdaExecute
3. Save changes.

Step 4: Execute the Step Function

1. Go to AWS Step Functions Console.


2. Select "ServerlessWorkflow".
3. Click "Start Execution" → Leave input empty → Click Start.
4. Monitor the Execution Flow:
o It should call StartFunction → ProcessFunction in sequence.
o Check Success Status.

Step 6: Monitor Logs (Optional)

1. Open AWS CloudWatch Console.


2. Navigate to Logs → Select the Lambda log groups.
3. Check for execution logs.

You might also like