```import pulumi from pulumi_aws import s3 import...
# general
a
Copy code
import pulumi
from pulumi_aws import s3

import pulumi
import pulumi_aws as aws


# Create an AWS resource (S3 Bucket)
bucket = s3.Bucket('my-bucket')

# Export the name of the bucket
pulumi.export('bucket_name', bucket.id)


size = 't2.micro'
ami = aws.get_ami(most_recent="true",
                  owners=[""],
                  filters=[{"name":"name","values":["amzn-ami-hvm-*"]}])

group = aws.ec2.SecurityGroup('webserver-secgrp',
    description='Enable HTTP access',
    ingress=[
        { 'protocol': 'tcp', 'from_port': 22, 'to_port': 22, 'cidr_blocks': ['0.0.0.0/0'] },
        { 'protocol': 'tcp', 'from_port': 80, 'to_port': 80, 'cidr_blocks': ['0.0.0.0/0'] }
    ])

user_data = """
#!/bin/bash
echo "Hello, World!" > index.html
nohup python -m SimpleHTTPServer 80 &
"""

server = aws.ec2.Instance('webserver-www',
    instance_type=size,
    vpc_security_group_ids=[group.id], # reference security group from above
    user_data=user_data,
    ami=ami.id)

pulumi.export('publicIp', server.public_ip)
pulumi.export('publicHostName', server.public_dns)
s
If you’re looking for an example of uploading an existing public key, you can use this blog post as an example: https://blog.scottlowe.org/2022/09/06/managing-aws-key-pairs-with-pulumi-and-go/
There’s also a link there to the API docs for
ec2.NewKeyPair
so that you can see what it looks like in other languages.