Tengo un servicio sin servidor ejecutándose con la siguiente configuración en el archivo serverless.yml:
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: '*' La función saveBookmark se parece a esto:
const params = { Bucket: process.env.TABLEAU_BOOKMARKS_BUCKET, Key: 'ABC123' } s3.headObject(params, (err, data) => { if (err) { console.log(err); } else { console.log(data); } }) Por alguna razón, recibo un error 403 cuando intento HEAD un archivo en el depósito que no existe. Después de analizar el problema, descubrí que debería agregar el permiso s3:ListBucket a la lista de permisos sin servidor para permitir el método headObject, lo cual hice. Esto no pareció tener ningún efecto ya que sigo obteniendo un 403 cuando intento dirigir un objeto en el balde.
El cubo no es público y cuando trato de usar el método putObject para cargar un archivo en el cubo, funciona bien. Además, cuando el archivo existe en el depósito, el método headObject funciona bien con un 403.
¿Por qué obtendría un 403 en lugar de un 404 cuando un archivo no está presente en un depósito?
Gracias
Intenta cambiar de
iamRoleStatements: - Effect: Allow Action: - s3:PutObject - s3:GetObject - s3:ListBucket Resource: "arn:aws:s3:::${self:custom.${self:provider.stage}.tableauBookmarksBucket}/*"para
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}"