diff --git a/README.md b/README.md index dd2609f..875742e 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,9 @@ A STAC API implementation using [stac-fastapi](https://github.com/stac-utils/sta ### [pgSTAC Titiler API](https://developmentseed.org/eoapi-cdk/#titilerpgstacapilambda-) A complete dynamic tiling API using [titiler-pgstac](https://github.com/stac-utils/titiler-pgstac) to create dynamic mosaics of assets based on [STAC Search queries](https://github.com/radiantearth/stac-api-spec/tree/master/item-search). Packaged as a complete runtime for deployment with API Gateway and Lambda and fully integrated with the pgSTAC Database construct. +### [STAC browser](https://developmentseed.org/eoapi-cdk/#stacbrowser-) +A CDK construct to host a static [Radiant Earth STAC browser](https://github.com/radiantearth/stac-browser) on S3. + ### [STAC Ingestor](https://developmentseed.org/eoapi-cdk/#stacingestor-) An API for large scale STAC data ingestion and validation into a pgSTAC instance. diff --git a/lib/index.ts b/lib/index.ts index 1dac133..6cfceb8 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -3,4 +3,5 @@ export * from "./bootstrapper"; export * from "./database"; export * from "./ingestor-api"; export * from "./stac-api"; -export * from "./titiler-pgstac-api"; \ No newline at end of file +export * from "./titiler-pgstac-api"; +export * from "./stac-browser"; \ No newline at end of file diff --git a/lib/stac-browser/index.ts b/lib/stac-browser/index.ts new file mode 100644 index 0000000..714b316 --- /dev/null +++ b/lib/stac-browser/index.ts @@ -0,0 +1,71 @@ +import { Stack, aws_s3 as s3, aws_s3_deployment as s3_deployment} from "aws-cdk-lib"; +import { RemovalPolicy, CfnOutput } from "aws-cdk-lib"; +import { PolicyStatement, ServicePrincipal, Effect } from "aws-cdk-lib/aws-iam"; + +import { Construct } from "constructs"; + + +export class StacBrowser extends Construct { + + public bucket: s3.Bucket; + public bucket_deployment: s3_deployment.BucketDeployment; + + constructor(scope: Construct, id: string, props: StacBrowserProps) { + super(scope, id); + + this.bucket = new s3.Bucket(this, 'Bucket', { + accessControl: s3.BucketAccessControl.PRIVATE, + removalPolicy: RemovalPolicy.DESTROY, + }) + + this.bucket.addToResourcePolicy(new PolicyStatement({ + sid: 'AllowCloudFrontServicePrincipal', + effect: Effect.ALLOW, + actions: ['s3:GetObject'], + principals: [new ServicePrincipal('cloudfront.amazonaws.com')], + resources: [this.bucket.arnForObjects('*')], + conditions: { + 'StringEquals': { + 'aws:SourceArn': props.cloudFrontDistributionArn + } + } + })); + + + this.bucket_deployment = new s3_deployment.BucketDeployment(this, 'BucketDeployment', { + destinationBucket: this.bucket, + sources: [s3_deployment.Source.asset(props.stacBrowserDistPath)] + }); + + new CfnOutput(this, "bucket-name", { + exportName: `${Stack.of(this).stackName}-bucket-name`, + value: this.bucket.bucketName, + }); + + } +} + +export interface StacBrowserProps { + + /** + * Location of the directory in the local filesystem that contains the STAC browser compiled code. + */ + readonly stacBrowserDistPath: string; + + + /** + * The ARN of the cloudfront distribution that will be added to the bucket policy with read access. + * + * @default - No cloudfront distribution ARN. The bucket policy will not be modified. + */ + readonly cloudFrontDistributionArn?: string; + + /** + * The name of the index document (e.g. "index.html") for the website. Enables static website + * hosting for this bucket. + * + * @default - No index document. + */ + readonly websiteIndexDocument?: string; + +}