No way to specify client context for local invoke
See original GitHub issueDescription
I am running a local service with start-lambda
and interacting with it from the Node SDK. It appears that the function ClientContext
is undefined
despite sending it correctly with the SDK.
There is also no way to specify ClientContext
with the local invoke
command.
Steps to reproduce
- Write a simple lambda function
exports.processEvents = function (event, context, callback) {
console.log("event", event)
console.log("context", context)
})
- Start local lambda service
$ sam local start-lambda
2019-05-13 17:48:27 Found credentials in shared credentials file: ~/.aws/credentials
2019-05-13 17:48:27 Starting the Local Lambda Service. You can now invoke your Lambda Functions defined in your template through the endpoint.
2019-05-13 17:48:27 * Running on http://127.0.0.1:3001/ (Press CTRL+C to quit)
- Invoke function with AWS SDK
#!/usr/bin/env node
var fs = require('fs');
var AWS = require('aws-sdk');
var Lambda = new AWS.Lambda({
endpoint: 'http://127.0.0.1:3001/',
});
Lambda.invoke({
ClientContext: new Buffer('{"apiKey": "abcd1234"}').toString('base64'),
FunctionName: "ProcessEventsFunction",
Payload: fs.readFileSync("event.json"),
}, function(err, data) {
console.log("err", err)
console.log("data", data)
})
Observed result
See that context.clientContext
is undefined
2019-05-13 17:52:30 Invoking index.processEvents (nodejs10.x)
Fetching lambci/lambda:nodejs10.x Docker container image......
2019-05-13 17:52:31 Mounting /Users/noah/dev/partnerapp/lambda as /var/task:ro,delegated inside runtime container
START RequestId: 52fdfc07-2182-154f-163f-5f0f9a621d72 Version: $LATEST
event: 'Registered',3Z 52fdfc07-2182-154f-163f-5f0f9a621d72
INFO event { type: 'track',
userId: 'test-user-23js8',
timestamp: '2019-04-08T01:19:38.931Z',
email: 'test@example.com',
properties: { plan: 'Pro Annual', accountType: 'Facebook' } }
succeed: [Function],4Z 52fdfc07-2182-154f-163f-5f0f9a621d72
INFO context { callbackWaitsForEmptyEventLoop: [Getter/Setter],
fail: [Function],
done: [Function],
functionVersion: '$LATEST',
functionName: 'test',
memoryLimitInMB: '128',
logGroupName: '/aws/lambda/test',
logStreamName: '2019/05/14/[$LATEST]ea74a58b6601ed93e4664022f15bf42d',
clientContext: undefined,
identity: undefined,
invokedFunctionArn: 'arn:aws:lambda:us-east-1:1178758407:function:test',
awsRequestId: '52fdfc07-2182-154f-163f-5f0f9a621d72',
getRemainingTimeInMillis: [Function: getRemainingTimeInMillis] }
END RequestId: 52fdfc07-2182-154f-163f-5f0f9a621d72
REPORT RequestId: 52fdfc07-2182-154f-163f-5f0f9a621d72 Duration: 19.25 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 46 MB
Expected result
Expect the ClientContext value sent with the Invoke API call would be available in my function.
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
- OS: OS X
sam --version
: SAM CLI, version 0.16.0
Issue Analytics
- State:
- Created 4 years ago
- Reactions:6
- Comments:6
Top Results From Across the Web
No way to specify client context for local invoke #1177 - GitHub
I am running a local service with start-lambda and interacting with it from the Node SDK. It appears that the function ClientContext is ......
Read more >Invoking Lambda functions locally - AWS Documentation
You can invoke your AWS Lambda function locally by using the sam local invoke AWS SAM CLI command and providing the function's logical...
Read more >Invoke Local - AWS Lambda - Serverless Framework
The invoke local command sets reasonable environment variables for the invoked function. All AWS specific variables are set to values that are quite...
Read more >lambda-local - npm
lambdaLocal.execute(options) ; callback, optional, lambda third parameter callback. When left out a Promise is returned ; clientContext, optional, ...
Read more >class Lambda. Client - Boto3 Docs 1.26.34 documentation
For details about how to configure different event sources, ... base64-encoded data about the invoking client to pass to the function in the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
+1
+1 This is definitely an important missing capability in sam.