Invoking an AWS Lambda Function from z/OS mainframe using AWS CLI

4 minute read
Content level: Intermediate
0

This article explains how to invoke an AWS Lambda Function from z/OS mainframe system using AWS Command Line Interface (AWS CLI)

Introduction

Using AWS CLI on your z/OS OMVS system, you gain access to all the functionalities that parallel the capabilities of the browser-based AWS Management Console. Whether you need to transfer files to and from Amazon S3, invoke an AWS Lambda function, integrate with GenAI or AI/ML services, or initiate an AWS Mainframe Modernization batch, the AWS CLI empowers you to harness the full potential of these offerings directly from your z/OS environment

AWS Lambda, a serverless computing service, provides an excellent option to integrate AWS Cloud services from mainframe application. By invoking AWS Lambda functions from a z/OS mainframe, you can extend the capabilities of your mainframe applications and take advantage of the scalability and flexibility of the cloud.

This article will guide you through the process of invoking an AWS Lambda function from a z/OS mainframe using the AWS Command Line Interface (CLI).

Prerequisites:

  • An active AWS account with appropriate permissions
  • AWS CLI installed and configured on your z/OS mainframe (refer to the step by step guidance on how to install AWS CLI on z/OS mainframe)
  • Network connection between AWS Cloud and mainframe

Create a AWS Lambda Function

  1. Follow the document to create a new AWS lambda function on AWS Console. Name the function as helloMainframe

  2. Here is simple sample python code for the Lambda function that will be invoked from AWS CLI. The code accepts a JSON string with key as name and return Hello, <name> !!.


import json

def lambda_handler(event, context):
    print("Name = " + event['name'])
    
    return 'Hello, ' + event['name'] + ' !!'

Run AWS CLI command to invoke AWS lambda function

This example invokes the Lambda function passing a JSON file as payload.

  1. On your mainframe, from TSO/ISPF panel on your mainframe use the 3.2 option to create a PS file. Then open the file using 3.4 option to add a record. While opening the file, on EDIT Entry Panel option make sure to select the Data Encoding as UTF-8.

EDIT Entry Panel

Add a JSON record as shown in the screenshot below. You may use a COBOL program as documented here to create the JSON records.

JSON Record

  1. Switch to OMVS command line. Run the command to copy the MVS PS file to an USS file.
cp -B "//'AWS.CLI.LAMBDA.INPUT'" lambda_input.json
  1. Invoke the AWS Lambda function helloMainframe from Command Line.
aws lambda invoke --function-name helloMainframe --payload file://lambda_input.json response.json

In this command:

  • --function-name helloMainframe specifies the name of the Lambda function you want to invoke.
  • --payload file://lambda_input.json specifies the path to the file containing the payload.
  • response.json is the file where the output from the Lambda function will be written.
  1. On successful invocation of the Lambda function you will see a response as below. The response.json file content will show a record - "Hello, Mainframe!!"
{
    "StatusCode": 200,
    "ExecutedVersion": "$LATEST"
}

You can also view the invocation of the AWS Lambda function on Monitor tab of Lambda service on AWS Console. You can also view the logs on Amazon CloudWatch.

Lambda Log

In this example, the Lambda function invocation is done manually from Command Line. The same commands can be invoked from Batch JCL using BPXBATCH program. Sample provided in the guidance.


References

[1] AWS Command Line Interface

[2] Access AWS services from IBM z/OS by installing the AWS CLI

[3] AWS Mainframe Modernization documentation