Skip to content

Commit

Permalink
feat: add STAC browser option
Browse files Browse the repository at this point in the history
  • Loading branch information
emileten committed Aug 22, 2023
1 parent daec1e0 commit b051a19
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
3 changes: 2 additions & 1 deletion lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export * from "./bootstrapper";
export * from "./database";
export * from "./ingestor-api";
export * from "./stac-api";
export * from "./titiler-pgstac-api";
export * from "./titiler-pgstac-api";
export * from "./stac-browser";
71 changes: 71 additions & 0 deletions lib/stac-browser/index.ts
Original file line number Diff line number Diff line change
@@ -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;

Check failure on line 10 in lib/stac-browser/index.ts

View workflow job for this annotation

GitHub Actions / package / Build and package

Property 'bucket' has no initializer and is not definitely assigned in the constructor.
public bucket_deployment: s3_deployment.BucketDeployment;

Check failure on line 11 in lib/stac-browser/index.ts

View workflow job for this annotation

GitHub Actions / package / Build and package

Property 'bucket_deployment' has no initializer and is not definitely assigned in the constructor.

constructor(scope: Construct, id: string, props: StacBrowserProps) {
super(scope, id);

const bucket = new s3.Bucket(this, 'Bucket', {
accessControl: s3.BucketAccessControl.PRIVATE,
removalPolicy: RemovalPolicy.DESTROY,
})

bucket.addToResourcePolicy(new PolicyStatement({
sid: 'AllowCloudFrontServicePrincipal',
effect: Effect.ALLOW,
actions: ['s3:GetObject'],
principals: [new ServicePrincipal('cloudfront.amazonaws.com')],
resources: [bucket.arnForObjects('*')],
conditions: {
'StringEquals': {
'aws:SourceArn': props.cloudFrontDistributionArn
}
}
}));


const browser_deployment = new s3_deployment.BucketDeployment(this, 'BucketDeployment', {

Check failure on line 35 in lib/stac-browser/index.ts

View workflow job for this annotation

GitHub Actions / package / Build and package

'browser_deployment' is declared but its value is never read.
destinationBucket: bucket,
sources: [s3_deployment.Source.asset(props.stacBrowserDistPath)]
});

new CfnOutput(this, "bucket-name", {
exportName: `${Stack.of(this).stackName}-bucket-name`,
value: bucket.bucketName,
});

}
}

export interface StacBrowserProps {

/**
* Location of the directory in the local filesystem that contains the STAC browser compiled code.
*/
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.
*/
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.
*/
websiteIndexDocument?: string;

}

0 comments on commit b051a19

Please sign in to comment.