Aws+codepipeline+alias plugin result to ServerlessError: The specified bucket does not exist

Hi there ,
I’m tryin g to setup pipeline for my lambda functions on AWS. the pipeline works when we just use serverless deploy --stage dev

But when i used serverless-aws-alia plugin , there are some errors.
serverless deploy --masterAlias uat --alias $env --force --package $CODEBUILD_SRC_DIR/target/$env -v -r ap-southeast-2

i handled many of them the last one is “ServerlessError: The specified bucket does not exist”

1-although i set alias =uat but sls try create resource with ‘-dev’ postfix .why?!
2-i granted full access to related role but at at last it can not create an S3 bucket

here is my yml file :
service: lambda-pipe
plugins:
- serverless-aws-alias-fixed
provider:
name: aws
runtime: nodejs12.x
environment:
STAGE: “${opt:stage, self:provider.stage}-uat”

functions:
  seiftime:
    handler: handler.seiftime
    events:
      - http:
          path: /time
          method: get
          request:
            parameters:
              querystrings:
                tz: true

buildspec.yml:
version: 0.2

phases:
  install:
    commands:
    - rm package-lock.json
    - npm install --silent --no-progress -g npm
    - npm install --silent --no-progress -g serverless
    - npm install --silent --no-progress  --save-dev serverless-aws-alias-fixed
    - npm --version
  pre_build:
    commands:
    - npm install --silent --no-progress
  build:
    commands:
    - npm run-script lint
    - npm run test
    - mkdir -p target/uat
    - serverless package --package target/uat  --stage uat  -v -r ap-southeast-2
artifacts:
  files:
  - target/**/*
  - serverless.yml
  - deploy.sh

My deploy.sh

export SLS_DEBUG=*

npm install -g serverless --unsafe-perm=true --allow-root

npm install --save-dev serverless-aws-alias-fixed --unsafe-perm=true --allow-root

#serverless deploy --stage $env --package $CODEBUILD_SRC_DIR/target/$env -v -r ap-southeast-2

serverless deploy --masterAlias uat --alias $env --force --package $CODEBUILD_SRC_DIR/target/$env -v -r ap-southeast-2

AWS Logs:

[Container] 2021/01/30 04:55:41 Waiting for agent ping
[Container] 2021/01/30 04:55:44 Waiting for DOWNLOAD_SOURCE
[Container] 2021/01/30 04:55:45 Phase is DOWNLOAD_SOURCE
[Container] 2021/01/30 04:55:45 CODEBUILD_SRC_DIR=/codebuild/output/src519598649/src
[Container] 2021/01/30 04:55:45 YAML location is /codebuild/readonly/buildspec.yml
[Container] 2021/01/30 04:55:45 Processing environment variables
[Container] 2021/01/30 04:55:46 No runtime version selected in buildspec.
[Container] 2021/01/30 04:55:46 Moving to directory /codebuild/output/src519598649/src
[Container] 2021/01/30 04:55:46 Registering with agent
[Container] 2021/01/30 04:55:46 Phases found in YAML: 1
[Container] 2021/01/30 04:55:46  BUILD: 1 commands
[Container] 2021/01/30 04:55:46 Phase complete: DOWNLOAD_SOURCE State: SUCCEEDED
[Container] 2021/01/30 04:55:46 Phase context status code:  Message: 
[Container] 2021/01/30 04:55:46 Entering phase INSTALL
[Container] 2021/01/30 04:55:46 Phase complete: INSTALL State: SUCCEEDED
[Container] 2021/01/30 04:55:46 Phase context status code:  Message: 
[Container] 2021/01/30 04:55:46 Entering phase PRE_BUILD
[Container] 2021/01/30 04:55:46 Phase complete: PRE_BUILD State: SUCCEEDED
[Container] 2021/01/30 04:55:46 Phase context status code:  Message: 
[Container] 2021/01/30 04:55:46 Entering phase BUILD
[Container] 2021/01/30 04:55:46 Running command bash deploy.sh
runing pwd
/codebuild/output/src519598649/src
runing ls .
deploy.sh
serverless.yml
target
runing whoami
root
running $CODEBUILD_SRC_DIR/target/$env
/codebuild/output/src519598649/src/target/uat
runing ls $CODEBUILD_SRC_DIR/target/$env
cloudformation-template-create-stack.json
cloudformation-template-update-stack.json
lambda-pipe.zip
serverless-state.json
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated request-promise-native@1.0.9: request-promise-native has been deprecated because it extends the now deprecated request package, see https://github.com/request/request/issues/3142
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
/usr/local/bin/serverless -> /usr/local/lib/node_modules/serverless/bin/serverless.js
/usr/local/bin/sls -> /usr/local/lib/node_modules/serverless/bin/serverless.js

> snappy@6.3.5 install /usr/local/lib/node_modules/serverless/node_modules/snappy
> prebuild-install || node-gyp rebuild


> protobufjs@6.10.2 postinstall /usr/local/lib/node_modules/serverless/node_modules/protobufjs
> node scripts/postinstall


> serverless@2.21.1 postinstall /usr/local/lib/node_modules/serverless
> node ./scripts/postinstall.js


   ┌───────────────────────────────────────────────────┐
   │                                                   │
   │   Serverless Framework successfully installed!    │
   │                                                   │
   │   To start your first project run 'serverless'.   │
   │                                                   │
   └───────────────────────────────────────────────────┘

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.3.1 (node_modules/serverless/node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.1: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

+ serverless@2.21.1
added 663 packages from 484 contributors in 33.466s
npm WARN saveError ENOENT: no such file or directory, open '/codebuild/output/src519598649/src/package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open '/codebuild/output/src519598649/src/package.json'
npm WARN src No description
npm WARN src No repository field.
npm WARN src No README data
npm WARN src No license field.

+ serverless-aws-alias-fixed@2.0.1
added 14 packages from 16 contributors and audited 14 packages in 1.059s

2 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

Serverless: To ensure safe major version upgrades ensure "frameworkVersion" setting in service configuration (recommended setup: "frameworkVersion: ^2.21.1")

Serverless: Load command interactiveCli
..
..
Serverless: Configuration warning at 'provider': unrecognized property 'alias'
Serverless:  
Serverless: Learn more about configuration validation here: http://slss.io/configuration-validation
Serverless:  
Serverless: Deprecation warning: Starting with next major version, default value of provider.lambdaHashingVersion will be equal to "20201221"
            More Info: https://www.serverless.com/framework/docs/deprecations/#LAMBDA_HASHING_VERSION_V2
Serverless: Deprecation warning: Starting with next major version, API Gateway naming will be changed from "{stage}-{service}" to "{service}-{stage}".
            Set "provider.apiGateway.shouldStartNameWithService" to "true" to adapt to the new behavior now.
            More Info: https://www.serverless.com/framework/docs/deprecations/#AWS_API_GATEWAY_NAME_STARTING_WITH_SERVICE
Serverless: Invoke deploy
Serverless: Invoke aws:common:validate
Serverless: Invoke aws:common:moveArtifactsToTemp
Serverless: Invoke aws:deploy:deploy
Serverless: WARNING: Inappropriate call of provider.request()
Serverless: WARNING: Inappropriate call of provider.request()
Serverless: [AWS cloudformation 400 0.062s 0 retries] listImports({ ExportName: 'lambda-pipe-dev-ServerlessAliasReference' })
Serverless: [AWS cloudformation 200 0.077s 0 retries] getTemplate({ StackName: 'lambda-pipe-dev', TemplateStage: 'Processed' })
Serverless: Preparing alias ...
Serverless: Processing custom resources
Serverless: Removing resources: 
Serverless: Processing functions
Serverless: Processing API
Serverless: Configuring stage
Serverless: Processing event source subscriptions
Serverless: Processing SNS Lambda subscriptions
Serverless: [AWS cloudformation 200 0.063s 0 retries] describeStacks({ StackName: 'lambda-pipe-dev' })
Serverless: WARNING: Inappropriate call of provider.request()
Serverless: [AWS cloudformation 400 0.055s 0 retries] describeStackResources({ StackName: 'lambda-pipe-dev-uat' })
Serverless: Creating Alias Stack 'uat' ...
Serverless: WARNING: Inappropriate call of provider.request()
Serverless: [AWS cloudformation 200 0.191s 0 retries] createStack({
  StackName: 'lambda-pipe-dev-uat',
  OnFailure: 'DELETE',
  Capabilities: [ 'CAPABILITY_IAM', 'CAPABILITY_NAMED_IAM', [length]: 2 ],
  Parameters: [ [length]: 0 ],
  TemplateBody: '{"AWSTemplateFormatVersion":"2010-09-09","Description":"Alias stack for lambda-pipe-dev (uat)","Resources":{"ServerlessAliasLogGroup":{"Type":"AWS::Logs::LogGroup","Properties":{"LogGroupName":"/serverless/lambda-pipe-dev-uat","RetentionInDays":7}}},"Outputs":{"ServerlessAliasName":{"Description":"Alias the stack represents.","Value":"uat"},"ServerlessAliasLogGroup":{"Description":"Log group for alias.","Value":{"Ref":"ServerlessAliasLogGroup"},"Export":{"Name":"lambda-pipe-dev-uat-LogGroup"}}}}',
  Tags: [
    { Key: 'STAGE', Value: 'dev' },
    { Key: 'ALIAS', Value: 'uat' },
    [length]: 2
  ]
})
Serverless: Checking Stack create progress...
Serverless: [AWS cloudformation 200 0.054s 0 retries] describeStackEvents({
  StackName: 'arn:aws:cloudformation:ap-southeast-2:688244660361:stack/lambda-pipe-dev-uat/865f45a0-62b7-11eb-accb-06770d237b36'
})
CloudFormation - CREATE_IN_PROGRESS - AWS::CloudFormation::Stack - lambda-pipe-dev-uat
CloudFormation - CREATE_IN_PROGRESS - AWS::Logs::LogGroup - ServerlessAliasLogGroup
CloudFormation - CREATE_IN_PROGRESS - AWS::Logs::LogGroup - ServerlessAliasLogGroup
CloudFormation - CREATE_COMPLETE - AWS::Logs::LogGroup - ServerlessAliasLogGroup
Serverless: [AWS cloudformation 200 0.045s 0 retries] describeStackEvents({
  StackName: 'arn:aws:cloudformation:ap-southeast-2:688244660361:stack/lambda-pipe-dev-uat/865f45a0-62b7-11eb-accb-06770d237b36'
})
CloudFormation - CREATE_COMPLETE - AWS::CloudFormation::Stack - lambda-pipe-dev-uat
Serverless: Stack create finished...
Serverless: [AWS cloudformation 200 0.061s 0 retries] describeStackResource({
  StackName: 'lambda-pipe-dev',
  LogicalResourceId: 'ServerlessDeploymentBucket'
})
Serverless: [AWS sts 200 0.805s 0 retries] getCallerIdentity({})
Serverless: Uploading CloudFormation file to S3...
Serverless: [AWS s3 404 0.053s 0 retries] putObject({
  Body: <Buffer 7b 22 41 57 53 54 65 6d 70 6c 61 74 65 46 6f 72 6d 61 74 56 65 72 73 69 6f 6e 22 3a 22 32 30 31 30 2d 30 39 2d 30 39 22 2c 22 44 65 73 63 72 69 70 74 ... 4221 more bytes>,
  Bucket: 'lambda-pipe-dev-serverlessdeploymentbucket-1p6x7ws3mh4oz',
  Key: 'serverless/lambda-pipe/uat/1611982489638-2021-01-30T04:54:49.638Z/compiled-cloudformation-template.json',
  ContentType: 'application/json',
  Metadata: { filesha256: 'w6Kx0jyr/itYumd6oHtynRziqKNwGox2kF819RsuQ6U=' }
})
 
  Serverless Error ---------------------------------------
 
  ServerlessError: The specified bucket does not exist
      at /usr/local/lib/node_modules/serverless/lib/plugins/aws/provider.js:1406:27
      at processTicksAndRejections (internal/process/task_queues.js:97:5)
 
  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Issues:        forum.serverless.com
 
  Your Environment Information ---------------------------
     Operating System:          linux
     Node Version:              12.16.1
     Framework Version:         2.21.1
     Plugin Version:            4.4.2
     SDK Version:               2.3.2
     Components Version:        3.6.0
 

[Container] 2021/01/30 04:56:44 Command did not exit successfully bash deploy.sh exit status 1
[Container] 2021/01/30 04:56:45 Phase complete: BUILD State: FAILED
[Container] 2021/01/30 04:56:45 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: bash deploy.sh. Reason: exit status 1
[Container] 2021/01/30 04:56:45 Entering phase POST_BUILD
[Container] 2021/01/30 04:56:45 Phase complete: POST_BUILD State: SUCCEEDED
[Container] 2021/01/30 04:56:45 Phase context status code:  Message:

I solved this issue.it seem packaging and then deploy is not working correctly with --alias plugin. i just used sls deploy and it works.