我是AWS Lambda的新手。我的问题是:在Jenkins(托管于AWS)中有一个RPM,通过“S3 artifacts”插件将其复制到S3存储桶中。我必须将此RPM从S3存储桶复制到其他EC2实例。是否有办法Lambda函数可以触发S3从S3复制RPM文件到EC2,以便在从Jenkins复制到S3后进行复制?
s3-plugin lambda
Jenkins--------------->S3----------->Ec2
我是AWS Lambda的新手。我的问题是:在Jenkins(托管于AWS)中有一个RPM,通过“S3 artifacts”插件将其复制到S3存储桶中。我必须将此RPM从S3存储桶复制到其他EC2实例。是否有办法Lambda函数可以触发S3从S3复制RPM文件到EC2,以便在从Jenkins复制到S3后进行复制?
s3-plugin lambda
Jenkins--------------->S3----------->Ec2
// imagine that the input variable is the JSON sended from the client.
//input = {
//s3_file_path : 'folder/folder1/file_name',
//bucket : 'your-bucket',
//};
// Use this library to connect easly with your EC2 instance.
var SSH = require('simple-ssh');
var fs = require('fs');
// This is the full S3 URL object that you need to download the file.
var s3_file_url = 'https://' + input.bucket + '.s3.amazonaws.com/' + input.s3_file_path;
/**************************************************/
/* SSH */
/**************************************************/
var ssh = new SSH({
host: 'YOUR-EC2-PUBLIC-IP',
user: 'USERNAME',
passphrase: 'YOUR PASSPHRASE', // If you have one
key : fs.readFileSync("../credentials/credential.pem") // The credential that you need to connect to your EC2 instance through SSH
});
// wget will download the file from the URL we passed
ssh.exec('wget ' + s3_file_url).start();
// Also, if you wanna download the file to another folder, just do another exec behind to enter to the folder you want.
ssh.exec('cd /folder/folder1/folder2').exec('wget ' + s3_file_url).start();
为了使此功能正常工作,您应确保启用EC2实例的权限,以便可以通过SSH进行访问。