A low-level client to interact locally with the AWS Greengrass Core in order to invoke other deployed Lambda functions.
import greengrasssdk
client = greengrasssdk.client('lambda')
These are the available methods:
Invokes a specific Lambda function.
In AWS Greengrass, you will need to specify the version that is deployed to Greengrass Core when invoking them by using the Qualifier field.
Request Syntax
response = client.invoke(
FunctionName='string',
InvocationType='Event'|'RequestResponse',
ClientContext='string',
Payload=b'bytes',
Qualifier='string'
)
[REQUIRED]
The Lambda function name.
You can specify Amazon Resource Name (ARN) of the function (for example, arn:aws:lambda:us-west-2:account-id:function:ThumbNail:1 ).
Using the ClientContext you can pass client-specific information to the Lambda function you are invoking. You can then process the client information in your Lambda function as you choose through the context variable.
The ClientContext JSON must be base64-encoded.
You can use this parameter to specify a Lambda function version that you are trying to invoke. The function version needs to match the one that was downloaded to GGC.
dict
Response Syntax
{
'Payload': StreamingBody(),
'FunctionError': 'string'
}
Response Structure
(dict) --
Upon success, returns an empty response. Otherwise, throws an exception.
Payload (StreamingBody) --
It is the object returned by the Lambda function. This is present only if the invocation type is RequestResponse .
In the event of a function error this field contains a message describing the error.
FunctionError (string) --
Indicates whether an error occurred while executing the Lambda function. If an error occurred this field will have Handled. Handled errors are errors that are reported by the function.
Examples
This operation invokes a Lambda function with client context
msg = json.dumps({
'message':'foobar'
})
client_context = json.dumps({
'custom':'custom text'
})
response = client.invoke(
ClientContext=base64.b64encode(bytes(client_context)),
FunctionName='arn:aws:lambda:us-west-2:123451234510:function:MyFunction',
InvocationType='RequestResponse',
Payload=msg,
Qualifier='1'
)
logger.info(response)
Expected Output:
{
'FunctionError': '',
'Payload': '?'
}
This operation invokes a Lambda function with client context and non-JSON payload. It only works if the target lambda is configured to receive binary data type.
client_context = json.dumps({
'custom':'custom text'
})
response = client.invoke(
ClientContext=base64.b64encode(bytes(client_context)),
FunctionName='arn:aws:lambda:us-west-2:123451234510:function:MyFunction',
InvocationType='RequestResponse',
Payload="Non-JSON Data",
Qualifier='1'
)
logger.info(response)
Expected Output:
{
'FunctionError': '',
'Payload': '?'
}