Search code examples
python-3.xamazon-web-servicesazure-devopssam

how to build, package and deploy AWS SAM lambda function of python from azure Devops CI/CD pipeline to AWS


I used the aws sam lambda function(hello_world) template to create a project. I can build, invoke locally and deploy from local using sam command. Now, the code is in Azure repo. I used "python package" to do pipeline and deploy but I do not know how can I build, package and deploy scripts of sam cmd? I searched google but did not get good resources or video.

Please give me some good resources, videos etc.


Solution

  • The following scripts work perfectly. It might help someone.

    - task: AWSShellScript@1
      displayName: 'Build'
      inputs:
        awsCredentials: AwsServiceConnection
        regionName: $(Region)
        scriptType: 'inline'
        inlineScript: |
          sam build --debug \
          --template-file template.yaml
    
    - task: AWSShellScript@1
      displayName: 'Package'
      inputs:
        awsCredentials: AwsServiceConnection
        regionName: $(Region)
        scriptType: 'inline'
        inlineScript: |
          sam package  --resolve-s3 (or it can be a bucket name. --s3-bucket <bucketname>)   --output-template-file packaged.yaml
    
    
    - task: AWSShellScript@1
      displayName: 'Deploy Infrastructure'
      inputs:
          awsCredentials: AwsServiceConnection
          regionName: $(Region)
          scriptType: "inline"
          inlineScript: |
            sam deploy \
            --template-file packaged.yaml \
            --no-confirm-changeset \
            --no-fail-on-empty-changeset \
            --capabilities CAPABILITY_IAM  \
            --stack-name test-dev-stack \
            --resolve-s3 \  ( or it can be a bucket name. --s3-bucket <bucketname>)
            --s3-prefix test-dev-stack