Karias Bolster
Karias Bolster

Reputation: 1035

Is there a way to specify an already created s3 deployment bucket in serverless?

So we are currently using serverless in our recent project and our client provided us the aws iam user because we will be deploying into their aws resources. The problem is that they won't give create s3 policy to the user. The creation of the s3 bucket will be done by them manually. So where in the serverless.yml can i add the s3 bucket they created and have serverless use it as a deployment bucket instead of creating a new one?

Upvotes: 1

Views: 3994

Answers (2)

Brian Winant
Brian Winant

Reputation: 3035

I think the OP is asking about how to specify the Serverless S3 deployment bucket, not how to reference a random bucket in a Lambda function.

You can set the deployment bucket in serverless.yml like this:

provider:
    deploymentBucket: <bucket name>

Upvotes: 10

Kevin Smith
Kevin Smith

Reputation: 14456

You can use parameters within the serverless application cloud formation script:

"Parameters" : {
  "S3BucketArn" : {
    "Default" : "arn:aws:s3:::somebucketarndefaults",
    "Description" : "The ARN for the S3 Bucket",
    "Type" : "String"
  }
}

I'm guessing you're using this in a serverless function (Lambda), so you can pass this using the environment variables

 "Resources" : {
    "MyAmazingFunction" : {
      "Type" : "AWS::Serverless::Function",
      "Properties": {
        "Handler": "functions::handle",
        // Yada yada
    "Environment" : {
          "Variables" : {
            "S3Arn": {"Ref" : "S3BucketArn"}
          }
        }
      }
    }

Then within the code just pull out the Arn using S3Arn environment variable.

Upvotes: 0

Related Questions