No way to specify client context for local invoke
- Dominant language
- Python
- Stars
- 6.7k
- Forks
- 1.2k
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 52
Description
### Description
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
1. Write a simple lambda function
```js
exports.processEvents = function (event, context, callback) {
console.log("event", event)
console.log("context", context)
})
```
2. Start local lambda service
```bash
$ 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)
```
3. Invoke function with AWS SDK
```js
#!/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`
```bash
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)
1. OS: OS X
2. `sam --version`: SAM CLI, version 0.16.0
Contributor guide
Assessment
This issue has not been assessed yet.