我正在尝试在由 AWS Lambda 创建的新 EC2 实例的 Userdata 字段中传递一个脚本(使用适用于 Javascript 的 AWS SDK,Node.js 6.10):
...
var paramsEC2 = {
ImageId: 'ami-28c90151',
InstanceType: 't1.micro',
KeyName: 'myawesomekwy',
MinCount: 1,
MaxCount: 1,
SecurityGroups: [groupname],
UserData:'#!/bin/sh \n echo "Hello Lambda"'
};
// Create the instance
ec2.runInstances(paramsEC2, function(err, data) {
if (err) {
console.log("Could not create instance", err);
return;
}
var instanceId = data.Instances[0].InstanceId;
console.log("Created instance", instanceId);
// Add tags to the instance
params = {Resources: [instanceId], Tags: [
{
Key: 'Name',
Value: 'taggggg'
}
]};
ec2.createTags(params, function(err) {
console.log("Tagging instance", err ? "failure" : "success");
});
});
...
我尝试了几件事,例如: - 创建一个字符串并将字符串传递给 UserData - 不工作 - 创建一个字符串并将其编码为 base64 并将字符串传递给 UserData - 不工作 - 粘贴 base64 编码的字符串 - 不工作
您能帮我理解如何在 UserData 中传递脚本吗?AWS SDK 文档有点缺乏。
是否也可以将放在 S3 存储桶中的脚本传递给 UserData?