Created
August 30, 2018 14:10
-
-
Save kuropen/104bb0952cb0e65af8aa89b5b23f8f79 to your computer and use it in GitHub Desktop.
Lambda function to generate 410 error
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
import boto3 | |
# このスクリプトをLambdaに入れ、API Gatewayで「Lambdaプロキシ統合」のエンドポイントを作成し、 | |
# パス「/」「/{proxy+}」に対してメソッド「ANY」でこのスクリプトに向ける。 | |
# エラーメッセージをS3に格納しているためIAMロールでS3へのアクセス権を設定する。 | |
# エラーメッセージの格納されたバケット名 | |
AWS_S3_BUCKET_NAME = 'becodon-503' | |
# エラーメッセージの格納されたオブジェクト名 | |
GET_OBJECT_KEY_NAME = '410.html' | |
def lambda_handler(event, context): | |
s3 = boto3.resource('s3') | |
obj = s3.Object(AWS_S3_BUCKET_NAME, GET_OBJECT_KEY_NAME) | |
response = obj.get() | |
body = response['Body'].read() | |
return { | |
"isBase64Encoded": False, | |
"statusCode": 410, | |
"headers": { "Content-Type": "text/html" }, | |
"body": body.decode('utf-8') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment