Skip to content

Instantly share code, notes, and snippets.

@pfeilbr
Created September 12, 2020 12:17
Show Gist options
  • Save pfeilbr/78db35ec7cac5886f771bc2d81e7aacd to your computer and use it in GitHub Desktop.
Save pfeilbr/78db35ec7cac5886f771bc2d81e7aacd to your computer and use it in GitHub Desktop.
react tsx/jsk cdk app
// pseudocode
const { ReactCDK, App, Stack } = require('@aws-cdk/react')
const Bucket = require('@aws-cdk/react/s3')
const { CloudFrontDistribution, Origins, DefaultOrigin } = require('@aws-cdk/react/cloudfront')
const { Api, Resource, Integration } = require('@aws-cdk/react/apigateway')
const Lambda = require('@aws-cdk/react/lambda')
const EchoLambda = (
<Lambda>
{
async ({event, context}) => ({
"statusCode": 200,
"headers": {
"Content-Type": "application/json"
}
"body: JSON.stringify(event)
})
}
</Lambda>
)
const EchoApi = (
<Api>
<Resource path="*">
<Integration type="lambda">
<EchoLambda />
</Integration>
</Resource>
</Api>
)
const WebsiteBucket = () => (
<Bucket src="./public" />
)
const MyCloudFrontDistribution = (
<CloudFrontDistribution>
<Origins>
<DefaultOrigin oai="true">
<WebsiteBucket />
</DefaultOrigin>
<Origin path="/api/*">
<EchoApi />
</Origin>
</Origins>
</CloudFrontDistribution>
)
const MyApp = (
<App>
<Stack>
<MyCloudFrontDistribution />
</Stack>
</App>
)
ReactCDK.render(MyApp, {region: 'us-east-1'})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment