Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

172
Visualizações
S3:HeadObject - returns 403 response

I have a serverless service running with the below configuration in the serverless.yml file:

service: tableau-export-rest

custom:
  dev:
    tableauBookmarksBucket: tmt-${self:provider.stage}-tableau-bookmarks
  qa:
    tableauBookmarksBucket: tmt-${self:provider.stage}-tableau-bookmarks
  prod:
    tableauBookmarksBucket: tmt-${self:provider.stage}-tableau-bookmarks

provider:
  name: aws
  runtime: nodejs12.x
  region: eu-west-1
  stage:  ${opt:stage, 'dev'}
  timeout: 900
  memorySize: 3008
  environment:
    TABLEAU_BOOKMARKS_BUCKET: ${self:custom.${self:provider.stage}.tableauBookmarksBucket}
  iamRoleStatements:
    - Effect: Allow
      Action:
        - s3:PutObject
        - s3:GetObject
        - s3:ListBucket
      Resource: "arn:aws:s3:::${self:custom.${self:provider.stage}.tableauBookmarksBucket}/*"
    - Effect: Allow
      Action:
        - lambda:InvokeFunction
      Resource: "arn:aws:lambda:*"

functions:
  saveBookmark:
    handler: index.saveBookmark
    timeout: 30
    events:
      - http:
          path: /save-bookmark
          method: post
          cors: 
            origin: '*'

The saveBookmark function looks something like this:

  const params = {
    Bucket: process.env.TABLEAU_BOOKMARKS_BUCKET,
    Key: 'ABC123'
  }

  s3.headObject(params, (err, data) => {
    if (err) {
      console.log(err);
    } else {
      console.log(data);
    }
  })

I am for some reason getting a 403 error when attempting to HEAD a file in the bucket which does not exist. After looking into the issue I discovered that I should add the permission s3:ListBucket to the list of serverless permissions to allow the headObject method which I did. This didn't seem to have any effect as I am still getting a 403 when trying to head an object in the bucket.

The bucket is not public and when I try to use the putObject method to upload a file into the bucket it works fine. Also, when the file exists in the bucket, the headObject method works just fine with a 403.

Why would I be getting a 403 instead of a 404 when a file is not present in a bucket?

Thanks

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Try changing from

iamRoleStatements:
    - Effect: Allow
      Action:
        - s3:PutObject
        - s3:GetObject
        - s3:ListBucket
      Resource: "arn:aws:s3:::${self:custom.${self:provider.stage}.tableauBookmarksBucket}/*"

to

iamRoleStatements:
    - Effect: Allow
      Action:
        - s3:PutObject
        - s3:GetObject
      Resource: "arn:aws:s3:::${self:custom.${self:provider.stage}.tableauBookmarksBucket}/*"
    - Effect: Allow
      Action: s3:ListBucket
      Resource: "arn:aws:s3:::${self:custom.${self:provider.stage}.tableauBookmarksBucket}"
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda