Slide 28
Slide 28 text
API Gatewayオリジン
カスタムヘッダー
CloudFrontで設定できるリ
クエストヘッダー
API Gatewayで検証すること
で直接アクセスを禁止する
// CloudFrontディストリビューションの作成
this.distribution = new cloudfront.Distribution(this, 'TodoDistribution', {
additionalBehaviors: {
'todos*': {
origin: new origins.RestApiOrigin(props.todoApi, {
originPath: '/prod',
customHeaders: {
'Referer': props.customReferer
},
}),
},
},
});
// API Gatewayの作成
this.api = new apigateway.RestApi(this, 'TodoApi', {
restApiName: 'Todo API',
defaultCorsPreflightOptions: {
allowHeaders: ['Content-Type', 'Authorization', 'Referer'],
},
policy: new iam.PolicyDocument({
statements: [
// カスタムヘッダーのRefererを検証するポリシー
new iam.PolicyStatement({
effect: iam.Effect.DENY,
principals: [new iam.AnyPrincipal()],
actions: ['execute-api:Invoke'],
resources: ['execute-api:/*'],
conditions: {
StringNotEquals: {
'aws:Referer': props.customReferer
}
}
})
]
}),
}),
28