让由 cdk exec 制作的 ec2 像 Dockerfile 一样启动脚本
我用这段代码创建了 ec2 实例。
const ec2Instance = new ec2.Instance(this, "Instance", {
vpc,
instanceType: ec2.InstanceType.of(
ec2.InstanceClass.T2,
ec2.InstanceSize.MICRO
),
machineImage: new ec2.AmazonLinuxImage({
generation: ec2.AmazonLinuxGeneration.AMAZON_LINUX_2,
cpuType: ec2.AmazonLinuxCpuType.X86_64,
}),
securityGroup: securityGroup,
keyName: "default_aws"
});
ec2
已正确制作,但是 int 中没有应用程序(当然)
通常,启动 ec2
后,我登录并执行一些命令,例如
sudo yum update
sudo yum install wget
sudo yum install emacs
我想要的构建 ec 2 时默认执行这些命令。
对于 Docker 映像,我可以在 Dockerfile 中编写命令
是否有任何等效的事情要做?
- 我检查了 ec2 aws UI 并发现了一些图像和模板,是否相关?
2)或者我可以在cdk
中有类似启动脚本的东西吗?
我想这可能是常见的要求,但我还找不到好的信息。
我的最终目标是让mysql用cdk安装ec2,但首先我需要了解ec2
启动脚本的基本思想
I made ec2
instance with this code.
const ec2Instance = new ec2.Instance(this, "Instance", {
vpc,
instanceType: ec2.InstanceType.of(
ec2.InstanceClass.T2,
ec2.InstanceSize.MICRO
),
machineImage: new ec2.AmazonLinuxImage({
generation: ec2.AmazonLinuxGeneration.AMAZON_LINUX_2,
cpuType: ec2.AmazonLinuxCpuType.X86_64,
}),
securityGroup: securityGroup,
keyName: "default_aws"
});
ec2
is correctly made but ,there is no application in int ( That's of course)
Normally, after starting the ec2
I log-in and do some commands such as
sudo yum update
sudo yum install wget
sudo yum install emacs
I want to exec these command as default when ec 2 is built.
For Docker image I can write the command in Dockerfile
Is there any equivalent things to do?
- I checked the ec2 aws UI and found some images and template, is it relevant?
2)Or Can I have something like start scripts in cdk
??
I guess It might be common requirement, though, I can't find good information yet.
My final goal is making mysql installed ec2 with cdk, but at first I need to understand the basic idea of ec2
start script
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将这些命令放入文件中并在脚本中读取该文件,如下所示:
You can put those commands in a file and read that file in the script like so: