Created
June 11, 2024 13:26
-
-
Save chandra-prakash-meghwal/4745cbb92122f60512b8a0c9911bb725 to your computer and use it in GitHub Desktop.
Python AWS lambda function which invokes another lambda
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import boto3 | |
import json | |
class LambdaClient: | |
def __init__(self, function_name): | |
self.function_name = function_name | |
self.client = boto3.client('lambda') | |
def invoke_function(self, payload): | |
response = self.client.invoke( | |
FunctionName=self.function_name, | |
InvocationType='RequestResponse', | |
Payload=json.dumps(payload) | |
) | |
return response['Payload'].read().decode('utf-8') | |
def lambda_handler(event, context): | |
lambda_client = LambdaClient('my_rest_service') | |
# Invoke the Lambda function | |
response = lambda_client.invoke_function({ | |
"action": "ping_rest_api" | |
}) | |
# Print the response from the Lambda function | |
print(response) | |
return { | |
'statusCode': 200, | |
'body': json.dumps('Hello from Lambda!') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment