Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd360458

Browse files
committed
adding Pandoc Lambda Layer
1 parent22464ba commitd360458

File tree

5 files changed

+45
-17
lines changed

5 files changed

+45
-17
lines changed

‎pandoc-s3-converter/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#Pandoc S3 Lambda converter
22

3-
Lambda function that waits for files uploaded to S3, converts them to docx using Pandoc and uploads back to S3.
3+
Lambda function that waits for files uploaded to S3, converts them to docx usingthe[PandocLambda Layer](https://github.com/effortless-serverless/pandoc-aws-lambda-binary)and uploads back to S3.
44

55
This example shows how to wire up S3 file conversion that runs an external processor, in this case[Pandoc](https://pandoc.org), a Swiss army knife for document conversion. Check out the[Running Pandoc on Lambda Guide](https://claudiajs.com/tutorials/pandoc-lambda.html) for more information.
66

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*global module, require, console, Promise */
2+
varchildProcess=require('child_process'),
3+
execPromise=function(command){
4+
'use strict';
5+
returnnewPromise(function(resolve,reject){
6+
childProcess.exec(command,function(err){
7+
if(err){
8+
reject(err);
9+
}else{
10+
resolve();
11+
}
12+
});
13+
});
14+
},
15+
spawnPromise=function(command,options){
16+
'use strict';
17+
returnnewPromise(function(resolve,reject){
18+
varprocess=childProcess.spawn(command,options);
19+
process.stdout.on('data',function(buffer){
20+
console.log(buffer.toString());
21+
});
22+
process.stderr.on('data',function(buffer){
23+
console.error(buffer.toString());
24+
});
25+
process.on('close',function(code){
26+
if(code!==0){
27+
reject(code);
28+
}else{
29+
resolve();
30+
}
31+
});
32+
});
33+
};
34+
module.exports={
35+
exec:execPromise,
36+
spawn:spawnPromise
37+
};

‎pandoc-s3-converter/convert.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ var path = require('path'),
33
fs=require('fs'),
44
os=require('os'),
55
uuid=require('uuid'),
6-
pandoc=require('pandoc-aws-lambda-binary'),
6+
pandocBinaryPath='/opt/bin/pandoc',
7+
cpPromise=require('./child-process-promise'),
78
s3=require('./s3-util');
89

910
module.exports=functionconvert(bucket,fileKey){
@@ -13,10 +14,9 @@ module.exports = function convert(bucket, fileKey) {
1314
returns3.download(bucket,fileKey).then(function(downloadedPath){
1415
sourcePath=downloadedPath;
1516
targetPath=path.join(os.tmpdir(),uuid.v4()+'.docx');
16-
returnpandoc(sourcePath,targetPath);
17+
returncpPromise.spawn(pandocBinaryPath,[sourcePath,'-o',targetPath]);
1718
}).then(function(){
1819
varuploadKey=fileKey.replace(/^in/,'out').replace(/\.[A-z0-9]+$/,'.docx');
19-
console.log('got to upload',targetPath,sourcePath);
2020
returns3.upload(bucket,uploadKey,targetPath);
2121
}).then(function(){
2222
console.log('deleting',targetPath,sourcePath);

‎pandoc-s3-converter/package.json‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,19 @@
44
"description":"Lambda function that waits for files uploaded to S3, converts them to docx using Pandoc and uploads back to S3",
55
"main":"index.js",
66
"scripts": {
7-
"start":"claudia create --region us-east-1 --handler main.handler --timeout 60 --memory 512",
7+
"start":"claudia create --region us-east-1 --handler main.handler --layers arn:aws:lambda:us-east-1:145266761615:layer:pandoc:1 --timeout 60 --memory 512",
88
"connect":"claudia add-s3-event-source --bucket pandoc-test-bucket --prefix in",
99
"update":"claudia update"
1010
},
1111
"author":"Gojko Adzic <gojko@gojko.com>",
1212
"license":"MIT",
1313
"dependencies": {
14-
"pandoc-aws-lambda-binary":"^1.1.0",
1514
"uuid":"^2.0.2"
1615
},
1716
"optionalDependencies": {
1817
"aws-sdk":"^2.6.2"
1918
},
2019
"devDependencies": {
21-
"claudia":"^4"
20+
"claudia":"^5.3.0"
2221
}
2322
}

‎pandoc-s3-converter/s3-util.js‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,12 @@ var aws = require('aws-sdk'),
3030
},uploadToS3=function(bucket,fileKey,filePath,acl){
3131
'use strict';
3232
console.log('uploading',bucket,fileKey,filePath,acl);
33-
returnnewPromise(function(resolve,reject){
34-
s3.upload({
33+
returns3.upload({
3534
Bucket:bucket,
3635
Key:fileKey,
3736
Body:fs.createReadStream(filePath),
3837
ACL:acl||'private'
39-
},function(error,result){
40-
if(error){
41-
reject(error);
42-
}else{
43-
resolve(result);
44-
}
45-
})
46-
});
38+
}).promise();
4739
};
4840

4941
module.exports={

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp