thousands-planet-78612
08/23/2021, 10:44 AM// this function defines our pulumi S3 static website in terms of the content that the caller passes in.
// this allows us to dynamically deploy websites based on user defined values from the POST body.
func createPulumiProgram(content string) pulumi.RunFunc {
return func(ctx *pulumi.Context) error {
// our program defines a s3 website.
// here we create the bucket
siteBucket, err := s3.NewBucket(ctx, "s3-website-bucket", &s3.BucketArgs{
Website: s3.BucketWebsiteArgs{
IndexDocument: pulumi.String("index.html"),
},
})
if err != nil {
return err
}
// here our HTML is defined based on what the caller curries in.
indexContent := content
// upload our index.html
if _, err := s3.NewBucketObject(ctx, "index", &s3.BucketObjectArgs{
Bucket: siteBucket.ID(), // reference to the s3.Bucket object
Content: pulumi.String(indexContent),
Key: pulumi.String("index.html"), // set the key of the object
ContentType: pulumi.String("text/html; charset=utf-8"), // set the MIME type of the file
}); err != nil {
return err
}
// Set the access policy for the bucket so all objects are readable.
if _, err := s3.NewBucketPolicy(ctx, "bucketPolicy", &s3.BucketPolicyArgs{
Bucket: siteBucket.ID(), // refer to the bucket created earlier
Policy: pulumi.Any(map[string]interface{}{
"Version": "2012-10-17",
"Statement": []map[string]interface{}{
{
"Effect": "Allow",
"Principal": "*",
"Action": []interface{}{
"s3:GetObject",
},
"Resource": []interface{}{
pulumi.Sprintf("arn:aws:s3:::%s/*", siteBucket.ID()), // policy refers to bucket name explicitly
},
},
},
}),
}); err != nil {
return err
}
// export the website URL
ctx.Export("websiteUrl", siteBucket.WebsiteEndpoint)
return nil
}
}
bored-table-20691
08/23/2021, 4:27 PMthousands-planet-78612
08/24/2021, 7:58 AMsiteBucket
variable to get s3 resources properties in the form of string i am having trouble converting the values into string .
Is there any thing i am missing.
func createPulumiProgram(content string, bname string) pulumi.RunFunc {
return func(ctx *pulumi.Context) error {
// our program defines a s3 website.
// here we create the bucket
siteBucket, err := s3.NewBucket(ctx, bname, &s3.BucketArgs{
Website: s3.BucketWebsiteArgs{
IndexDocument: pulumi.String("index.html"),
},
})
if err != nil {
return err
}
Region := siteBucket.Region
BucketDomainName := siteBucket.BucketDomainName
Bucket := siteBucket.Bucket
}
I would like to store the following infromation in DB and that why i am trying to convert the value to string however sitebucket
returns pulumi.string format which i can not store in DB.
"outputs": {
"accelerationStatus": "",
"acl": "private",
"arn": "arn:aws:s3:::s3-website-bucket-7a7e85d",
"bucket": "s3-website-bucket-7a7e85d",
"bucketDomainName": "<http://s3-website-bucket-7a7e85d.s3.amazonaws.com|s3-website-bucket-7a7e85d.s3.amazonaws.com>",
"bucketRegionalDomainName": "<http://s3-website-bucket-7a7e85d.s3.us-east-2.amazonaws.com|s3-website-bucket-7a7e85d.s3.us-east-2.amazonaws.com>",
"corsRules": [],
"forceDestroy": false,
"grants": [],
"hostedZoneId": "Z2O1EMRO9K5GLX",
"id": "s3-website-bucket-7a7e85d",
"lifecycleRules": [],
"loggings": [],
"objectLockConfiguration": null,
"region": "us-east-2",
"replicationConfiguration": null,
"requestPayer": "BucketOwner",
"serverSideEncryptionConfiguration": null,
"tags": {},
"versioning": {
"enabled": false,
"mfaDelete": false
},
bored-table-20691
08/24/2021, 4:42 PMthousands-planet-78612
08/25/2021, 12:40 PM