Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save chandra-prakash-meghwal/4745cbb92122f60512b8a0c9911bb725 to your computer and use it in GitHub Desktop.
Save chandra-prakash-meghwal/4745cbb92122f60512b8a0c9911bb725 to your computer and use it in GitHub Desktop.
Python AWS lambda function which invokes another lambda
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