Is there a way to get the final code bundle S3 key?

I’m trying to include some extra CFN resources to create an Elastic Beanstalk application as part of my stack (some of my code needs to run as a daemon). The code to run on EB is in my serverless codebase. The final S3 key for the uploaded code is calculated during deployment and accessed within the serverless code is artifactDirectoryName. Is there a way to access that as a serverless variable in my CFN resources in serverless.yml? If not, should it be possible to write a plugin to expose it? I haven’t tried plugin development yet but would be willing to try if it sounded possible.

If you need to reference it from CFN, can you get it via a Ref? The S3 bucket resource returns its name from a Ref call.

Otherwise, I think this is something you could probably get via a plugin, but I’m not familiar with the workings of EB to give more detail.

I know I can get the S3 bucket as declared in serverless.yml, but I need the full path to the code bundle that sls deploy uploads. I want to reference that full path in my CFN template that is declared in serverless.yml. I looked into writing a plugin, but it looks like all variables are expanded before any plugins run (including mine and the deploy plugin that generates the full artifact path), so I don’t think there’s a way to do it.

Did you figure out how to get this full path?

I ended up writing a plugin that modifies my CFN template. Here’s an example. This was written in February, so I don’t know what might have changed in Serverless since then…

'use strict';

const path = require('path');

class CodeArtifactLocator {
    constructor(serverless) {
        this.serverless = serverless;

        this.hooks = {
            'before:deploy:deploy': this.beforeDeploy.bind(this)

    beforeDeploy() {
        const key = `${this.serverless.service.package.artifactDirectoryName}/${this.serverless.service.package.artifact.split(path.sep).pop()}`;

        if(this.serverless.service.resources && this.serverless.service.resources.MyBeanstalkApplicationVersion) {
            this.serverless.service.resources.MyBeanstalkApplicationVersion.Properties.SourceBundle.S3Key = key

module.exports = CodeArtifactLocator;