def pulumi_program(): # Create a bucket and expose a website index document site_bucket = s3.Bucket("s3-website-bucket", website=s3.BucketWebsiteArgs(index_document="index.html")) index_content = """ <html> <head><title>Hello S3</title><meta charset="UTF-8"></head> <body> <p>Hello, world!</p> <p>Made with ❤️ with <a href="https://pulumi.com">Pulumi</a></p> </body> </html> """ # Write our index.html into the site bucket s3.BucketObject("index", bucket=site_bucket.id, # reference to the s3.Bucket object content=index_content, key="index.html", # set the key of the object content_type="text/html; charset=utf-8") # set the MIME type of the file # Set the access policy for the bucket so all objects are readable s3.BucketPolicy("bucket-policy", bucket=site_bucket.id, policy={ "Version": "2012-10-17", "Statement": { "Effect": "Allow", "Principal": "*", "Action": ["s3:GetObject"], # Policy refers to bucket explicitly "Resource": [pulumi.Output.concat("arn:aws:s3:::", site_bucket.id, "/*")] }, }) # Export the website URL pulumi.export("website_url", site_bucket.website_endpoint)
def create_pulumi_program(content: str): # Create a bucket and expose a website index document site_bucket = s3.Bucket( "s3-website-bucket", website=s3.BucketWebsiteArgs(index_document="index.html")) index_content = content # Write our index.html into the site bucket s3.BucketObject("index", bucket=site_bucket.id, content=index_content, key="index.html", content_type="text/html; charset=utf-8") # Set the access policy for the bucket so all objects are readable s3.BucketPolicy( "bucket-policy", bucket=site_bucket.id, policy={ "Version": "2012-10-17", "Statement": { "Effect": "Allow", "Principal": "*", "Action": ["s3:GetObject"], # Policy refers to bucket explicitly "Resource": [pulumi.Output.concat("arn:aws:s3:::", site_bucket.id, "/*")] }, }) # Export the website URL pulumi.export("website_url", site_bucket.website_endpoint)
def create_static_website(bucket_name, title, body): # Create a bucket and expose a website index document site_bucket = s3.Bucket( bucket_name, bucket=bucket_name, website=s3.BucketWebsiteArgs(index_document="index.html")) index_content = f""" <html> <head> <title>{title}</title> <meta charset="UTF-8"></head> <body>{body}</body> </html> """ # Write our index.html into the site bucket s3.BucketObject( "index", bucket=site_bucket.id, # reference to the s3.Bucket object content=index_content, key="index.html", # set the key of the object content_type="text/html; charset=utf-8" ) # set the MIME type of the file # Set the access policy for the bucket so all objects are readable s3.BucketPolicy( "bucket-policy", bucket=site_bucket.id, policy={ "Version": "2012-10-17", "Statement": { "Effect": "Allow", "Principal": "*", "Action": ["s3:GetObject"], # Policy refers to bucket explicitly "Resource": [pulumi.Output.concat("arn:aws:s3:::", site_bucket.id, "/*")] }, }) # Export the website URL pulumi.export("website_url", site_bucket.website_endpoint)
def create_s3website_bucket(bucket_name): bucket = s3.Bucket( bucket_name, bucket=bucket_name, acl="public-read", website=s3.BucketWebsiteArgs( index_document="index.html", error_document="404.html", ), tags={ "Website": WEBSITE_DOMAIN_NAME, "Environment": "dev", }, ) bucket_id = bucket.id bucket_policy = s3.BucketPolicy( bucket_name + "-bucket-policy", bucket=bucket_id, policy=bucket_id.apply(public_access_policy_for_s3website_bucket)) return bucket
def __init__(self, name: str, args: StaticPageArgs, props: Optional[dict] = None, opts: Optional[ResourceOptions] = None) -> None: super().__init__('xyz:index:StaticPage', name, props, opts) # Create a bucket and expose a website index document. bucket = s3.Bucket( f'{name}-bucket', website=s3.BucketWebsiteArgs(index_document='index.html'), opts=ResourceOptions(parent=self)) # Create a bucket object for the index document. s3.BucketObject( f'{name}-index-object', bucket=bucket.bucket, key='index.html', content=args.index_content, content_type='text/html', opts=ResourceOptions(parent=bucket)) # Set the access policy for the bucket so all objects are readable. s3.BucketPolicy( f'{name}-bucket-policy', bucket=bucket.bucket, policy=bucket.bucket.apply(_allow_getobject_policy), opts=ResourceOptions(parent=bucket)) self.bucket = bucket self.website_url = bucket.website_endpoint self.register_outputs({ 'bucket': bucket, 'websiteUrl': bucket.website_endpoint, })
"""An AWS Python Pulumi program""" import pulumi from pulumi_aws import s3 # Create an AWS resource (S3 Bucket) bucket = s3.Bucket('my-bucket', website=s3.BucketWebsiteArgs( index_document="index.html", )) # Export the name of the bucket pulumi.export('bucket_name', bucket.id) bucketObject = s3.BucketObject( 'index.html', acl='public-read', content_type='text/html', bucket=bucket, content=open('site/index.html').read(), ) pulumi.export('bucket_endpoint', pulumi.Output.concat('http://', bucket.website_endpoint))