Skip to content

Instantly share code, notes, and snippets.

@kuropen
Created August 30, 2018 14:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kuropen/104bb0952cb0e65af8aa89b5b23f8f79 to your computer and use it in GitHub Desktop.
Save kuropen/104bb0952cb0e65af8aa89b5b23f8f79 to your computer and use it in GitHub Desktop.
Lambda function to generate 410 error
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