-
Notifications
You must be signed in to change notification settings - Fork 459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(docs): Add serverless application guide #786
Conversation
Looks interesting. Some possible future changes to the example:
|
Thank you for the great feedback, @jsteinich!
We need to use the web hosting feature of the S3 bucket to serve the
I thought about that as well. However it didn't feel right. Currently the frontend has ~10ish files that are deployed to the S3 Bucket, however that number could grow substantially for a bigger application. This would result in the same number of (generated) S3 bucket object resources in Terraform.
Great idea. Noted.
Done. |
Makes sense. For some reason I was thinking it was single file |
Here's some code that we have: private VariableConditionResource<CloudfrontOriginAccessIdentity> ApplyBucketPolicy(S3Bucket bucket)
{
{//public
var publicBucketPolicy = new PolicyDocument
{
Statements = {new S3().ToGetObject().OnObject(Config.WebSiteDomain, "*").ForPublic()}
};
new VariableConditionResource<S3BucketPolicy>(!Config.UseCloudFront,
new S3BucketPolicy(this, "public_s3_policy", new S3BucketPolicyConfig
{
Bucket = bucket.Id,
Policy = publicBucketPolicy.ToJson()
}), true);
}
{//cloudfront
new VariableConditionResource<S3BucketPublicAccessBlock>(Config.UseCloudFront,
new S3BucketPublicAccessBlock(this, "access_block", new S3BucketPublicAccessBlockConfig
{
Bucket = bucket.Id,
IgnorePublicAcls = true
}));
var accessIdentity = new VariableConditionResource<CloudfrontOriginAccessIdentity>(Config.UseCloudFront,
new CloudfrontOriginAccessIdentity(this, "cf_access_identity", new CloudfrontOriginAccessIdentityConfig
{
Comment = "Access S3 bucket content only through CloudFront"
}));
var cfBucketPolicy = new PolicyDocument
{
Statements =
{
new S3().ToGetObject().OnObject(Config.WebSiteDomain, "*")
.For(accessIdentity.StringValue(nameof(accessIdentity.Resource.IamArn)))
}
};
new VariableConditionResource<S3BucketPolicy>(Config.UseCloudFront,
new S3BucketPolicy(this, "cf_s3_policy", new S3BucketPolicyConfig
{
Bucket = bucket.Id,
Policy = cfBucketPolicy.ToJson()
}));
return accessIdentity;
}
}
//within cloud front distribution
Origin = new ICloudfrontDistributionOrigin[]
{
new CloudfrontDistributionOrigin
{
DomainName = bucket.BucketDomainName,
OriginId = $"s3-origin-{bucket.Id}",
OriginPath = "",
S3OriginConfig = new ICloudfrontDistributionOriginS3OriginConfig[]
{
new CloudfrontDistributionOriginS3OriginConfig
{
OriginAccessIdentity = cfAccessIdentity.StringValue(nameof(cfAccessIdentity.Resource.CloudfrontAccessIdentityPath))
}
}
}
}, |
Thanks @jsteinich! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quite a different style from my version, but I like it!
I'm going to lock this pull request because it has been closed for 30 days. This helps our maintainers find and focus on the active issues. If you've found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
Adds a guide explaining the end to end serverless example.
rendered version
Repo with end to end serverless example: https://github.com/hashicorp/cdktf-integration-serverless-example (also linked in guide)
What do you think having this guide inside the newly created
docs/full-guide
directory? Happy to move it elsewhere if that seems off.Resolves #733