@baluenex

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

serverless frameworkに認証付きでformdataを送りたい

解決したいこと

バックエンドにserverless frameworkを使っております。
front(Vue2)からAPI Gatewayにファイルを送る処理を作成しています。
ymlで

headers: '*'

にしてAuthorizationヘッダーなしで実装するとLambdaで受け取りを確認できるのですが、下記ソースの状態でリリースした後にcognitoで発行したidTokenをAuthorizationヘッダーに付与すると、401エラーを吐いて届きません。
フロントの問題か、ymlの問題か区別がついていないので、見ていただけると嬉しいです。

Javascript

axios.post(
  `${process.env.VUE_APP_API_ENDPOINT}/upload_files?username=${this.username}`,
  formData,
  {
    headers: {
      "Authorization": this.$store.getters.idToken,
      "Content-Type": "multipart/form-data"
    }
  }
).then(function(response) {
  console.log(response)
}).catch(function(error) {
  console.log(error)
})

serverless.yml(functionを一部抜粋)

uploadFiles:
  handler: index_directory.upsert
  name: ${self:provider.stage}_upload_files
  events:
    - http:
        path: /upload_files
        method: post
        cors:
          origin: '*'
          headers:
            - Authorization
            - Content-Type
        integration: lambda
        authorizer:
          type: COGNITO_USER_POOLS
          authorizerId: !Ref ApiGatewayWithAuthorizationAuthorizer
0 likes

No Answers yet.

Your answer might help someone💌