Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to deploy 20+ lambdas using aws-sam-deploy pipe

we have 20 + lambdas with 100+ end points, need to deployed with AWS SAM templates. Please suggest the best approach and please provide the sample scripts/templates if any.

1 answer

1 accepted

0 votes
Answer accepted

@koti r  Hi. Thanks for your question. Maybe this article can help you.

 

Regards, Igor.

Hi Igor Stoyanov, Thanks for sharing with me, but I have one query related to the same. Please find the details below.

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
            deploymentTest
            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 * .[^.]*
              - pipeatlassian/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 * .[^.]*
              - pipeatlassian/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 * .[^.]*
              - pipeatlassian/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
            deploymentTest
            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 * .[^.]*
              - pipeatlassian/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 * .[^.]*
              - pipeatlassian/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 * .[^.]*
              - pipeatlassian/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

@koti r  hi. What you ask is under development: Support multi-step deployments 

Also i found a question related to your problem: https://community.atlassian.com/t5/Bitbucket-questions/The-deployment-environment-test-in-your-bitbucket-pipelines-yml/qaq-p/971584

maybe you can find some useful info there.
Regards, Igor

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bitbucket

⭐ Calling all Bitbucket and DevOps experts: Special showcase opportunity ⭐

Hi, Bitbucket community! Are you a DevOps practitioner (or know one in your network)? Do you have DevOps tips, tricks, or learnings you'd like to share with the community? If so, we'd love to hea...

1,481 views 4 7
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you