我正在尝试在由 AWS Lambda 创建的新 EC2 实例的 Userdata 字段中传递脚本(使用 AWS SDK for Javascript, 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'
} …Run Code Online (Sandbox Code Playgroud)amazon-ec2 amazon-web-services aws-sdk aws-lambda aws-sdk-nodejs