Skip to content

Instantly share code, notes, and snippets.

@nyawach
Created November 28, 2019 09:45
Show Gist options
  • Save nyawach/23006246971a6939f1a14b1aece6c24e to your computer and use it in GitHub Desktop.
Save nyawach/23006246971a6939f1a14b1aece6c24e to your computer and use it in GitHub Desktop.
やることとしてはこんな感じ Lambda 以外でもできる - header の + `Content-Type` に `application/force-download` を追加 + `Content-disposition` に `attachment; filename=<ダウンロード時のファイル名>` を追加 - レスポンスボディに保存したいデータを記述
import { APIGatewayProxyHandler } from "aws-lambda"
export const handler: APIGatewayProxyHandler = async event => {
const filename = "data.json"
return {
statusCode: 200,
headers: {
"Content-Type": "application/force-download",
"Content-disposition": `attachment; filename=${filename}`,
},
body: JSON.stringify({
"id": 1,
"name": "test-user",
}),
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment