EC2 user data in CDK

0

Anyone know or has examples of bash scripts in user data for an EC2 instance when using CDK?

질문됨 4년 전2534회 조회
1개 답변
0
수락된 답변

This is a simple example from the @aws-cdk/aws-ec2 core library.

this.instance.addUserData('yum install -y https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/linux_amd64/amazon-ssm-agent.rpm');

https://github.com/aws/aws-cdk/blob/48c26c2f59cb8c30a592af98a367f59d0995f5f3/packages/%40aws-cdk/aws-ec2/lib/bastion-host.ts#L136

It uses the addUserData method on the ec2.Instance class. You just pass it a list of commands and it adds the commands to the user data script. https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-ec2.Instance.html#add-wbr-user-wbr-datacommands

A more complicated example can be seen in the @aws-cdk/aws-eks core library. There is a renderUserData function that creates a list of commands to add to the user data.

AWS
답변함 4년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠