Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Regarding deployment to multiple environments

koti r January 7, 2022

In our architecture, we have to deploy 20 lambdas, each lambda is deployed through a separate template which is in root folder of the code and we have three different environments like Test, Staging and Production. When i tried to deploy lambda1 in 3 environments, it is working fine, but when i try to deploy lambda2 into 3 environments, getting error like environment defined multiple times. Please find the sample code and error attached here. Any help for this solution is highly appreciated. Thanks in advance.

 

pipelines:
  default:
        - step:
            name:  lambda1 deployement
            deployment: Test
            caches:  
              - node
            condition:
                changesets:
                    includePaths:
                     
                      - "folder/subfolder/lambda1/*.js"
                      - "folder/subfolder/lambda1/package*.json"
                     

            script:
              - cd folder/subfolder/lambda1
              - npm install
              - apt-get update
              - apt-get install zip
              - zip -r ../lambda1.zip * .[^.]*
              - pipe: atlassian/aws-sam-deploy:1.3.1
                variables:
                  AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
                  AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
                  AWS_DEFAULT_REGION: 'myregion'
                  S3_BUCKET: 'mybucket'
                  STACK_NAME: 'lambda1'    
                  SAM_TEMPLATE: '../../../template.yaml'  
                  CAPABILITIES: ['CAPABILITY_IAM', 'CAPABILITY_AUTO_EXPAND']
        - step:
            name:  lambda1 deployement
            deployment: Staging
            caches:  
              - node
            condition:
                changesets:
                    includePaths:
                     
                      - "folder/subfolder/lambda1/*.js"
                      - "folder/subfolder/lambda1/package*.json"
                     

            script:
              - cd folder/subfolder/lambda1
              - npm install
              - apt-get update
              - apt-get install zip
              - zip -r ../lambda1.zip * .[^.]*
              - pipe: atlassian/aws-sam-deploy:1.3.1
                variables:
                  AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
                  AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
                  AWS_DEFAULT_REGION: 'myregion'
                  S3_BUCKET: 'mybucket'
                  STACK_NAME: 'lambda1'    
                  SAM_TEMPLATE: '../../../template.yaml'  
                  CAPABILITIES: ['CAPABILITY_IAM', 'CAPABILITY_AUTO_EXPAND']
        - step:
            name:  lambda1 deployement
            deployment: Production
            caches:  
              - node
            condition:
                changesets:
                    includePaths:
                     
                      - "folder/subfolder/lambda1/*.js"
                      - "folder/subfolder/lambda1/package*.json"
                     

            script:
              - cd folder/subfolder/lambda1
              - npm install
              - apt-get update
              - apt-get install zip
              - zip -r ../lambda1.zip * .[^.]*
              - pipe: atlassian/aws-sam-deploy:1.3.1
                variables:
                  AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
                  AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
                  AWS_DEFAULT_REGION: 'myregion'
                  S3_BUCKET: 'mybucket'
                  STACK_NAME: 'lambda1'    
                  SAM_TEMPLATE: '../../../template.yaml'  
                  CAPABILITIES: ['CAPABILITY_IAM', 'CAPABILITY_AUTO_EXPAND']
        - step:
            name:  lambda2 deployement
            deployment: Test
            caches:  
              - node
            condition:
                changesets:
                    includePaths:
                     
                      - "folder/subfolder/lambda2/*.js"
                      - "folder/subfolder/lambda2/package*.json"
                     

            script:
              - cd folder/subfolder/lambda2
              - npm install
              - apt-get update
              - apt-get install zip
              - zip -r ../lambda2.zip * .[^.]*
              - pipe: atlassian/aws-sam-deploy:1.3.1
                variables:
                  AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
                  AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
                  AWS_DEFAULT_REGION: 'myregion'
                  S3_BUCKET: 'mybucket'
                  STACK_NAME: 'lambda2'    
                  SAM_TEMPLATE: '../../../template.yaml'  
                  CAPABILITIES: ['CAPABILITY_IAM', 'CAPABILITY_AUTO_EXPAND']
        - step:
            name:  lambda2 deployement
            deployment: Staging
            caches:  
              - node
            condition:
                changesets:
                    includePaths:
                     
                      - "folder/subfolder/lambda2/*.js"
                      - "folder/subfolder/lambda2/package*.json"
                     

            script:
              - cd folder/subfolder/lambda2
              - npm install
              - apt-get update
              - apt-get install zip
              - zip -r ../lambda2.zip * .[^.]*
              - pipe: atlassian/aws-sam-deploy:1.3.1
                variables:
                  AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
                  AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
                  AWS_DEFAULT_REGION: 'myregion'
                  S3_BUCKET: 'mybucket'
                  STACK_NAME: 'lambda2'    
                  SAM_TEMPLATE: '../../../template.yaml'  
                  CAPABILITIES: ['CAPABILITY_IAM', 'CAPABILITY_AUTO_EXPAND']
        - step:
            name:  lambda2 deployement
            deployment: Production
            caches:  
              - node
            condition:
                changesets:
                    includePaths:
                     
                      - "folder/subfolder/lambda2/*.js"
                      - "folder/subfolder/lambda2/package*.json"
                     

            script:
              - cd folder/subfolder/lambda2
              - npm install
              - apt-get update
              - apt-get install zip
              - zip -r ../lambda2.zip * .[^.]*
              - pipe: atlassian/aws-sam-deploy:1.3.1
                variables:
                  AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
                  AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
                  AWS_DEFAULT_REGION: 'myregion'
                  S3_BUCKET: 'mybucket'
                  STACK_NAME: 'lambda2'    
                  SAM_TEMPLATE: '../../../template.yaml'  
                  CAPABILITIES: ['CAPABILITY_IAM', 'CAPABILITY_AUTO_EXPAND']
If I do so the error is like, defined test or staging or production in multiple times. How can i deploy 20 lambdas whenever there is a change in the corresponding code. Please suggest. Thank you

1 answer

0 votes
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 11, 2022

Hi @koti r,

I'm afraid that a certain deployment environment cannot be used more than once in a certain pipeline.

In the yml file that you shared here, you are using only one pipeline (default) and all 3 environments are used multiple times in that pipeline.

We have a feature request to support multi-step deployments, which I think would provide a solution for your use case:

As per the latest update there, our team has been working on this and the feature should be ready early this year. You can add yourself as a watcher in that feature request (by selecting the Start watching this issue link) if you'd like to get notified via email on updates.

In the meantime, one way to work around this issue would be to create custom pipelines, one for each lambda.
Each custom pipeline could include 3 steps, one for each deployment environment.

Custom pipelines are not triggered automatically on every push, you could either trigger them manually or on schedule:

https://support.atlassian.com/bitbucket-cloud/docs/pipeline-triggers/#On-schedule

Kind regards,
Theodora

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events