Reputation: 189
Starting a few hours today, a simple curl command on Lambda is failing.
Lambda environment is NodeJs 10.x (have also tried in 12.x).
const { execSync } = require('child_process');
exports.handler = async (event) => {
execSync('curl http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/images/BigBuckBunny.jpg -o /tmp/BigBuckBunny.jpg');
const response = {
statusCode: 200,
body: JSON.stringify('Hello from Lambda!'),
};
return response;
};
I get a /bin/sh curl: command not found error Any idea what the issue is?
Response:
{
"errorType": "Error",
"errorMessage": "Command failed: curl http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/images/BigBuckBunny.jpg -o /tmBigBuckBunny.jpg\n/bin/sh: curl: command not found\n",
"trace": [
"Error: Command failed: curl http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/images/BigBuckBunny.jpg -o /tmBigBuckBunny.jpg",
"/bin/sh: curl: command not found",
"",
" at checkExecSyncError (child_process.js:621:11)",
" at execSync (child_process.js:657:15)",
" at Runtime.exports.handler (/var/task/index.js:11:4)",
" at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)"
]
}
Upvotes: 6
Views: 12062
Reputation: 189
Finally i have a confirmation from Amazon support (and their internal tech team) that CURL binary is no longer included as part of the AWS Lambda environment based on Amazon Linux 2. Which is why I am not able to perform curl using either execSync or spawnSync in Node 10 and Node 12.
The alternative as per them is to use the "requests" library https://github.com/request/request/blob/master/README.md#streaming
Upvotes: 10
Reputation: 49
I tried using spawnSync instead of execSync and it's working.
const {spawnSync} = require('child_process');
The spawnSync
uses a process environment to run your command, while an execSync
uses a shell environment.The curl path is apparently not configured in the shell environment.
Upvotes: 2