How to deploy to a specific object key inside an S3 Bucket with the Serverless framework?

Viewed 586

Serverless framework configuration allows:

deploymentBucket:
    name: foo

However, it always creates a serverless object key inside the foo bucket. I want to be able to deploy to a different key like BAR.

deploymentBucket:
    name: foo/BAR # illustration only, doesn't work

What are my options here?

3 Answers

I don't believe Serverless has this functionality.

Your options are

  • Raise a GitHub issue and hope someone adds the functionality for you, or
  • Write a Serverless plugin that lets you add prefixes to the objects inside the deployment bucket

I found this sample config file and it contains a bucket name prefixed by a serverless module path.

deploymentBucket:
    name: com.serverless.${self:provider.region}.deploys # Deployment bucket name. Default is generated by the framework
    serverSideEncryption: AES256 # when using server-side encryption

This is a complete shot in the dark, but if you want to write to foo/BAR, maybe this setting would work for you:

name: com.serverless.${self:provider.region}.foo.BAR

EDIT: Does changing the package name affect which key the deployment is written to?

Here is example with putting index.html.

I'm not that much familiar with serverless framework, so hope it helps.

Related