-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to invoke lambda functions? #9
Comments
You need to use the fork here that's had it's routes updated to support the lambda SDK... Then you can invoke against it with the lambda sdk i.e. let lambda = new AWS.Lambda({region: 'ap-southeast-2', endpoint: 'http://localhost:3000' })
var lambda_args = {
"data": "Hello World"
}
var params = {
FunctionName: 'servicename-prd-functionname', // name of the serverless function you are going to execute as if it was deployed with the default serverless stage
Payload: JSON.stringify(lambda_args)
};
lambda.invoke(params, function(err, data) {
if (err) {
console.error(err);
} else {
console.dir(data);
}
}) |
Hey @ned-kelly, currently using your fork and receiving:
in serverless-offline-direct-lambda/proxy.js:6:74. whenever I set up my serverless offline server and then using aws cli to invoke the function hosted by the server. I'm invoking based on these params:
where data is a key value json. Can you provide me some assistance? |
I also receive this error when I try to do a serverless deploy with serverless-offline-direct-lambda
|
@suwilliam @ned-kelly how can I install the fork from npm? |
@ndelvalle You can just do |
@suwilliam have you found a workaround on this one? I'm currently getting the same, trying to figure out if it's some weird configuration issue / not setting headers correctly perhaps?
|
Hi guys, sorry for the delay - I'm not actively getting github notification emails hence the slow delay... So you should be able to invoke the function without API gateway (I'm using it this way).... You need to ensure that your // Simple script to test we can invoke the lambda function locally - from another lambda function...
var AWS = require('aws-sdk');
AWS.config.region = 'ap-southeast-2';
let lambda = new AWS.Lambda({
region: 'ap-southeast-2',
endpoint: 'http://localhost:4000'
})
var lambda_args = {
"some_key": "value",
"magic_answer": 42
}
var params = {
FunctionName: 'name-of-function', // the lambda function we are going to invoke
Payload: JSON.stringify(lambda_args)
};
lambda.invoke(params, function(err, data) {
if (err) {
console.error(err);
} else {
console.dir(data);
}
}) And your lambda function would be written like any other normal lambda function... // Example for API Gateway Response
exports.handler = (event, context, callback) => {
callback(null, {
statusCode: 200,
body: JSON.stringify({
message: 'it worked',
input: event,
}),
});
};
// Callback without API Gateway headers can be just like any other regular JS callback
exports.handler = (event, context, callback) => {
callback(null, {
key: "value",
other_key: 42,
});
}; |
I am struggling to actually invoke a function with
AWS.lambda.invoke()
Can you perhaps provide a full example?
Using the example code, I have tried all permutations of the following:
Lambda setup
Invocation type
Payload
Lambda invoke
They all say
Unsupported Media Type
What am I doing wrong?
The text was updated successfully, but these errors were encountered: