Skip to content

Instantly share code, notes, and snippets.

@pfeilbr

pfeilbr/index.jsx

Created Sep 12, 2020
Embed
What would you like to do?
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