relevant code that i have:
"""An AWS Python Pulumi program"""
import os
import boto3
import pulumi
import pulumi_aws as aws
from pulumi import StackReference
def wait_for_instance_running(instance_id, region):
ec2 = boto3.client('ec2', region=region)
<http://pulumi.log.info|pulumi.log.info>(
msg="Waiting for Instance to pass healthchecks",
ephemeral=True,
)
waiter = ec2.get_waiter('instance_status_ok')
waiter.wait(InstanceIds=[instance_id])
<http://pulumi.log.info|pulumi.log.info>(msg="Instance is running and passed healthchecks", ephemeral=True)
def wait_for_s3_created(bucket_id, region):
s3 = boto3.client('s3', region=region)
<http://pulumi.log.info|pulumi.log.info>(
msg="Waiting for bucket to be ready",
ephemeral=True,
)
# <https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3/waiter/BucketExists.html>
waiter = s3.get_waiter('bucket_exists')
waiter.wait(Bucket=bucket_id)
<http://pulumi.log.info|pulumi.log.info>(msg="Bucket has been created", ephemeral=True)
config = pulumi.Config()
instance_type = config.get("instanceType")
base_stack = StackReference(f"net-cfg")
region = base_stack.get_output("region")
# TODO: need a way to reference aws:region from a diff stack and use it in this stack
# currently forced to do this manually using CLU before calling `pulumi up`
# Look up the latest Amazon Linux 2 AMI.
ami = aws.ec2.get_ami(
filters=[aws.ec2.GetAmiFilterArgs(
name="name", values=["amzn2-ami-hvm-*"],
)],
owners=["amazon"], most_recent=True,
).id
# Create an AWS resource (S3 Bucket)
bucket = aws.s3.Bucket('my-bucket')
# try to make the thing wait till bucket ID is ready
bucket.id.apply(lambda bucket_id: wait_for_s3_created(bucket_id))
user_data = """#!/bin/bash
echo "Hello, World from Pulumi!" > index.html
touch /etc/environment && S3_BUCKET_ID=%s
nohup python -m SimpleHTTPServer 80 &
""" % str(bucket.id) # doesn't work
# Create and launch an EC2 instance into the public subnet.
server = aws.ec2.Instance("server",
instance_type=instance_type,
subnet_id=base_stack.get_output("subnet_id"),
vpc_security_group_ids=base_stack.get_output("vpc_security_group_ids"),
user_data=user_data,
ami=ami,
tags={"Name": "debo-testing-pulumi"},
)
# # Export the name of the bucket
pulumi.export('bucket_name', bucket.id)