EC2 user data in CDK


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

asked 3 years ago555 views
1 Answer
Accepted Answer

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

this.instance.addUserData('yum install -y');

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.

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.

answered 3 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions