Код: Выделить всё
import boto3
from botocore.exceptions import NoCredentialsError, PartialCredentialsError
def get_lambda_client():
return boto3.client('lambda')
def invoke_lambda():
lambda_client = get_lambda_client()
if lambda_client:
try:
response = lambda_client.invoke(
FunctionName='MyLambdaFunctionName',
InvocationType='RequestResponse', # or 'event for async invocation'
Payload=b'{}' #Not sending any payload
)
print(f" the response from the aws = {response}")
except Exception as e:
print(f" Error invoking Lambda function: {e}")
invoke_lambda()
- Политика для запуска функции Lambda
Код: Выделить всё
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "lambda:InvokeFunction", "Resource": "< arn of my lambda function>" }, { "Effect": "Allow", "Action": "sts:AssumeRole", "Resource": "< arn of the role I created for lambda function which intern will trigger aws step function>" } ] } - Доверенная политика для роли, которую я создал для этого триггера функции Lambda
Код: Выделить всё
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Service": "lambda.amazonaws.com", "AWS": "" }, "Action": "sts:AssumeRole" } ] }
Код: Выделить всё
Error invoking Lambda function: An error occurred (ExpiredTokenException) when calling the Invoke operation: The security token included in the request is expired
Подробнее здесь: https://stackoverflow.com/questions/790 ... ocal-setup