serverless-heaven / serverless-aws-alias

Alias support for Serverless 1.x
MIT License
189 stars 68 forks source link

Invalid tag when deploying masterAlias #191

Open kortac opened 4 years ago

kortac commented 4 years ago

When deploying masterAlias with command

SLS_DEBUG=* sls deploy --verbose --masterAlias

it fails with the following error:

ServerlessError: Expected params.Tags[1].Value to be a string
      at /Users/***/WebstormProjects/***/node_modules/serverless/lib/plugins/aws/provider/awsProvider.js:327:27
      at runMicrotasks (<anonymous>)
      at processTicksAndRejections (internal/process/task_queues.js:94:5)

Reason for this is because serverless-aws-alias tries to add a tag with a boolean value:

Serverless: [AWS cloudformation undefined 0.004s 0 retries] createStack({
  StackName: '***',
  OnFailure: 'DELETE',
  Capabilities: [ 'CAPABILITY_IAM', 'CAPABILITY_NAMED_IAM', [length]: 2 ],
  Parameters: [ [length]: 0 ],
  TemplateBody: '{"AWSTemplateFormatVersion":"2010-09-09","Description":"Alias stack for *** (true)","Resources":{"ServerlessAliasLogGroup":{"Type":"AWS::Logs::LogGroup","Properties":{"LogGroupName":"/serverless/***-true","RetentionInDays":7}}},"Outputs":{"ServerlessAliasName":{"Description":"Alias the stack represents.","Value":"true"},"ServerlessAliasLogGroup":{"Description":"Log group for alias.","Value":{"Ref":"ServerlessAliasLogGroup"},"Export":{"Name":"***-true-LogGroup"}}}}',
  Tags: [
    { Key: 'STAGE', Value: 'production' },
    { Key: 'ALIAS', Value: true },
    [length]: 2
  ]
})

Versions: serverless 1.61.2 serverless-aws-alias 1.8.0 serverless-domain-manager 4.0.0

kortac commented 4 years ago

Applying this patch file fixes the error:

diff --git a/node_modules/serverless-aws-alias/lib/createAliasStack.js b/node_modules/serverless-aws-alias/lib/createAliasStack.js
index adadc43..2a674f0 100644
--- a/node_modules/serverless-aws-alias/lib/createAliasStack.js
+++ b/node_modules/serverless-aws-alias/lib/createAliasStack.js
@@ -16,7 +16,7 @@ module.exports = {

        this._serverless.cli.log(`Creating Alias Stack '${this._alias}' ...`);
        const stackName = `${this._provider.naming.getStackName()}-${this._alias}`;
-       let stackTags = { STAGE: this._options.stage, ALIAS: this._alias };
+       let stackTags = { STAGE: this._options.stage, ALIAS: this._alias.toString() };

        // Merge additional stack tags
        if (_.isObject(this._serverless.service.provider.stackTags)) {
diff --git a/node_modules/serverless-aws-alias/lib/updateAliasStack.js b/node_modules/serverless-aws-alias/lib/updateAliasStack.js
index 15e7ec2..76b0c80 100644
--- a/node_modules/serverless-aws-alias/lib/updateAliasStack.js
+++ b/node_modules/serverless-aws-alias/lib/updateAliasStack.js
@@ -13,7 +13,7 @@ module.exports = {
        this._serverless.cli.log('Creating alias stack...');

        const stackName = `${this._provider.naming.getStackName()}-${this._alias}`;
-       let stackTags = { STAGE: this._options.stage, ALIAS: this._alias };
+       let stackTags = { STAGE: this._options.stage, ALIAS: this._alias.toString() };
        const templateUrl = `https://s3.amazonaws.com/${this.bucketName}/${this._serverless.service.package.artifactDirectoryName}/compiled-cloudformation-template-alias.json`;
        // Merge additional stack tags
        if (_.isObject(this._serverless.service.provider.stackTags)) {
@@ -49,7 +49,7 @@ module.exports = {

        this.serverless.cli.log('Updating alias stack...');
        const stackName = `${this._provider.naming.getStackName()}-${this._alias}`;
-       let stackTags = { STAGE: this._options.stage, ALIAS: this._alias };
+       let stackTags = { STAGE: this._options.stage, ALIAS: this._alias.toString() };

        // Merge additional stack tags
        if (_.isObject(this._serverless.service.provider.stackTags)) {
m0ai commented 4 years ago

I got the same issues too on serverless-aws-alias 1.8.0. think this bug will affect not only me and issues writer but also many users using 1.8.0 version. 😭

m0ai commented 4 years ago

@SpaceHeroGuide, how thinking about considering opening a pull request for it?

njdullea commented 3 years ago

Same issue