Search code examples
amazon-web-servicesaws-lambdaaws-cliaws-samaws-sam-cli

How can I download/pull lambda code to a local machine from command line?


I am using the sam deploy command with the AWS SAM command line tool to deploy. Now I made some changes with the web IDE in the AWS Console. How can I pull the changes to the local machine, so that the next sam deploy command won't override them? (I am looking for something similar to a git pull I guess)


Solution

  • To do this you will need to use the AWS CLI, the start of this process will require you to use the get-function function in the AWS CLI.

    This will return a pre signed URL in the Code > Location structure, if you then download this (using a CLI tool such as curl) you can then download a zip file containing the contents of the Lambda function.

    The expected function would look similar to the below

    curl $(aws lambda get-function --function-name $FUNCTION_NAME --output text --query "Code.[Location]")