1. Creating a Security Group and Attaching It to an EC2 Instance
Start by initializing your Pulumi program. In the code snippet below, we create an S3 Bucket (for demonstration), set up a security group for our web server, configure security rules, and launch an EC2 instance with the security group attached.pulumi up, you might encounter a connection error when testing SSH connectivity. For example:
Ensure that your security group allows SSH access. If you experience a timeout, verify that the ingress rule for port 22 is correctly configured.

2. Generating a Clickable DNS URL for Your Instance
Instead of manually copying the public IP address, you can output a clickable URL using the instance’s public DNS. Update your outputs as follows:pulumi up, the output will display similar values:
3. Creating Multiple EC2 Instances Using a Loop
To efficiently create multiple EC2 instances, define an array of instance names and iterate over it. In the example below, three instances (“web1”, “web2”, and “web3”) are created, and their public IP addresses are collected for output.pulumi up execution, Pulumi will detect that the original “web-server” instance is no longer needed. It will remove it and create the three new instances. The terminal output will reflect these changes:
4. Monitoring Your Pulumi Deployment
After running an update, click the provided URL in the output to access the Pulumi dashboard. This dashboard offers a detailed view of the recent update, including resource creation, updates, or deletions. It also provides a comprehensive timeline of configuration changes and deployment events.
The Pulumi dashboard is a powerful tool for tracking your deployment progress and understanding resource changes. Make sure to explore it after every update for better insight.
5. Cleaning Up Resources
When you are finished with the demonstration, you can remove all resources from your stack by running:This lesson demonstrated how to create and manage security groups and EC2 instances using Pulumi. From outputting useful connection information to scaling your deployment with a loop, you now have a solid foundation for using Pulumi in your infrastructure projects. Happy coding!