0
votes

I'm using the new pipelines module in aws-cdk to build a multi account code-pipeline deploying a spring boot application to beanstalk.
I followed this tutorial and implemented my own subclass of Cdk.Stage.
This stage class creates a new backend stack:

export class BackendStack extends cdk.Stack {
    constructor(scope: cdk.Construct, id: string, artifact: Artifact, props?: cdk.StackProps) {
        super(scope, id, props);

        const image = new DockerImageAsset(this, 'backend-image', {
            directory: path.join(__dirname, '..', '..', '..', 'backend'),
            buildArgs: {
                'JAR_FILE': './target/app.jar'
            },

        })

        const dockerRunFile = {
            "AWSEBDockerrunVersion": "1",
            "Ports": [
                {
                    "ContainerPort": 8080,
                    "HostPort": 8080
                }
            ],
            "Image": {
                "Name": image.imageUri
            }

        }
        fs.writeFileSync(path.join(__dirname, 'Dockerrun.aws.json'), JSON.stringify(dockerRunFile));

        const versionAsset = new Asset(this, 'version-asset', {
            path: path.join(__dirname, 'Dockerrun.aws.json')
        })

        const appVersionProps = new CfnApplicationVersion(this, 'backend-app-version', {
            applicationName: appName,
            sourceBundle: {
                s3Bucket: versionAsset.bucket.bucketName,
                s3Key: versionAsset.s3ObjectKey
            }

        });
    }
...
}

Unfortunately the image.imageUri resolves to Token[TOKEN.219] and not the correct image URI. I think this has to do with the resolution of Cloudformation tokens. In my opinion I have to delay the creation of the Dockerrun.aws.json but I don't know how to achieve that.

Is there any other way to pass assets like the Dockerrun.aws.json file to the backend stack ?
I need it to deploy the beanstalk application correctly.

1

1 Answers

1
votes

As you pointed out correctly, the resolution of tokens happens inside CloudFormation, so you cannot write it to a file. Is there a way to not use a real file but to provide the sourceBundle inline in CFN? Then CDK would generate a correct GetAtt inside your template to reference the uploaded file.

But please make sure you activated the newStyle synth so it might work when it uses hard-coded strings instead of parameters then. You need the new bootstrapping for this.

Be aware that all this is not GA yet.