Last active
September 2, 2022 10:34
-
-
Save zxkane/2390e1acfb2a9168bb2aa0cd58b5ac45 to your computer and use it in GitHub Desktop.
todo-restful-api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const cloudFrontS3 = new CloudFrontToS3(this, 'control-plane', { | |
insertHttpSecurityHeaders: false, | |
cloudFrontDistributionProps: { | |
comment: 'It is managed by ServerlessTODO app.', | |
minimumProtocolVersion: SecurityPolicyProtocol.TLS_V1_2_2019, | |
httpVersion: HttpVersion.HTTP2_AND_3, | |
additionalBehaviors: { | |
['/prod/*']: { | |
origin: new HttpOrigin(Fn.select(2, Fn.split('/', api.url)), { | |
protocolPolicy: OriginProtocolPolicy.HTTPS_ONLY, | |
}), | |
viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS, | |
cachePolicy: new CachePolicy(this, 'customCachePolicy', { | |
defaultTtl: Duration.seconds(0), | |
minTtl: Duration.seconds(0), | |
maxTtl: Duration.seconds(1), | |
enableAcceptEncodingGzip: true, | |
enableAcceptEncodingBrotli: true, | |
headerBehavior: CacheHeaderBehavior.allowList('authorization'), | |
}), | |
allowedMethods: AllowedMethods.ALLOW_ALL, | |
}, | |
}, | |
}, | |
}); | |
new BucketDeployment(this, 'DeployWebsite', { | |
sources: [ | |
Source.asset(path.join(__dirname, '../frontend/dist/'), { | |
exclude: [], | |
}), | |
], | |
destinationBucket: cloudFrontS3.s3Bucket!, | |
destinationKeyPrefix: '/', | |
prune: false, | |
retainOnDelete: false, | |
cacheControl: [CacheControl.maxAge(Duration.days(7))], | |
storageClass: StorageClass.INTELLIGENT_TIERING, | |
distribution: cloudFrontS3.cloudFrontWebDistribution, | |
distributionPaths: ['/index.html',], | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"subject":"my-memo", | |
"description":"hello world!!", | |
"dueDate":1661926828 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#set($dueDate = $input.path('$.dueDate')) | |
#set($subject = "$util.escapeJavaScript($input.path('$.subject'))") | |
#set($description = "$util.escapeJavaScript($input.path('$.description'))") | |
{ | |
"TableName": "${table.tableName}", | |
"Key": { | |
"id": { | |
"S": "todo-$context.requestId" | |
} | |
}, | |
"UpdateExpression": "set subject = :s, description = :d, dueDate = :dd, createdTimeInMills = :ct", | |
"ExpressionAttributeValues": { | |
":s": { | |
"S": "$subject" | |
}, | |
":d": { | |
"S": "$description" | |
}, | |
":dd": { | |
"N": "$dueDate" | |
}, | |
":ct": { | |
"N": "$context.requestTimeEpoch" | |
} | |
}, | |
"ConditionExpression": "attribute_not_exists(id)", | |
"ReturnValues": "ALL_NEW" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"subject": "$util.escapeJavaScript($input.path('$.Attributes.subject.S')).replaceAll(\"\\\\'\",\"'\")", | |
"description": "$util.escapeJavaScript($input.path('$.Attributes.description.S')).replaceAll(\"\\\\'\",\"'\")", | |
"id": "$input.path('$.Attributes.id.S')", | |
"createdTimeInMills": $input.path('$.Attributes.createdTimeInMills.N'), | |
"dueDate": $input.path('$.Attributes.dueDate.N') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment