使用CLI下载Lambda代码

时间:2018-03-01 07:01:59

标签: amazon-web-services amazon-s3 aws-lambda aws-cli

计划对我们的Lambda代码进行代码修订。为了实现自动化,我尝试使用AWS Lambda CLI的get-function

它返回包含代码位置的配置信息。

例如:

{
"Code": {
    "RepositoryType": "S3",
    "Location": "https://awslambda-eu-cent-1-tasks.s3.eu-central-1.amazonaws.com/snapshots/893116096348/test-a3930794-73f7-431c-8818-7ad20a925f41?versionId=7dS2j2LWXsg7iGVCrKqeuhfnZwa2u8Ua&X-Amz-Security-Token=FQoDYXdzENT%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FwEaDB2pAx%2Bj8eAbaojFEiK9A%2FDOgDmOdXmGOb3I2527X32yV3Mg9t%2BvJp242BuRZ7xK8PsRw3o4O36nCeLp%2Fxb42%2Fdv1%2BVXlKPPastT%2FIvVEjh3BrP7y5T%2BHV5DnOZZW5I5JzgpXSr%2B8lQ%2BR4K4hzthrxA%2FI5BnyH0BsqNs6mIGYEWt7CSYUkaF1xSJADwhP7%2BH7%2BvmYs%2B3goom%2BS6GrV1vHVG%2BtCk8XR7scFcY%2B9hF9b%2F9lhm2WH2DruLdSZcme39pmO%2BuUwMCUQF9aCyJYXByx2bct4f2CAIB2our4hZDSRZghwFjPkxJRVY121oK%2FP8kKEJRNsy%2FPMYAIJMR%2BjCIdd%2F60c4Hvn0B6JwBfRuS2icqXfsEov%2BpYfVCCYjlFRunVmDeLq1XsxvZrBInMk%2FLwN%2BwzlxqvFycsqp7wwQ9vOIJdPAZhWDrb72yD1OIaWJJuQYYDY%2FPmqIMblfab8AjMNxqbACejCef0wOQ80%2BC3I9vO%2BKo9e0hOp3jDJqb4CpmSMefbPA%2FBtY8YcXOYoxluEXZwXEjn3LC%2Fr6%2FpUYeQM6cF%2FPEbOxQbbbqsSh2ArnwdXmZyurpgYOh7ijCrm7jzDidOn8hrFEQVWcHlhIowpba1AU%3D&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20180228T124052Z&X-Amz-SignedHeaders=host&X-Amz-Expires=600&X-Amz-Credential=ASIAJYREVQ2BVFLE62EA%2F20180228%2Feu-central-1%2Fs3%2Faws4_request&X-Amz-Signature=7141182cd7eb3199658baa4a3fca531504785b0b1981c7479a25277612d6f7b7"
},
"Configuration": {
    "TracingConfig": {
        "Mode": "PassThrough"
    },
    "Version": "$LATEST",
    "CodeSha256": "XAzdNmTvD4i***********sfbtV6M=",
....
....

此s3下载网址仅在10分钟内有效,并且在我尝试使用浏览器时成功下载代码为zip。

我尝试使用卷曲而没有运气。我只返回一些不可读的输出。

  卷曲 - 请求GET \     --ur' https://awslambda-eu-cent-1-tasks.s3.eu-central-1.amazonaws.com/snapshots/893116096348/test-a3930794-73f7-431c-8818-7ad20a925f41?versionId=7dS2j2LWXsg7iGVCrKqeuhfnZwa2u8Ua&X-Amz-Security-Token=FQoDYXdzEOb%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FwEaDB2EkvqColpALM8B9yK9A2mMT53lTPAb%2BVHb04ZvtcSDMvZ7IFPGfexhKD9mgailYhr2w3KZdYfLUJSJTDsdpwjjS8QzzFczUdgpqeGrbtH5%2BLzc8xe%2B6hWEFIm6L15xSX%2FDbpIoR01RHLUifmztjd%2BWT%2B11jUuhjC4Kkjsut5Bw63ARZSOjTSmnCT8kCqse%2FWLxnrBQN4vlM2UaOLYsD6l3L6oHlEzLfuCOaoes6N%2FXretbKNg%2FIPyarBIPN%2Ff56Etova2sv%2BG1E9AIJXbini1I6gspEq1NnN48lxX3E35WGG6mbCfhyYgsHc620%2ByXDeT7pB7rJ7R%2BqRbsCqkLT6t1iwljXKFtrrFxc9wUfUh14cho0HEtDbyQWfR%2BLqVzW6XkwqsIepCUBcXiJGPsiPfqh82nEFnpRsGcf%2FNZcIgPPTvW8JMCZJD5DLjbYffZoKj%2BOLOiVL3rice%2F7WyoN2ogxh%2FIGT1RJPhpw4J%2B%2BkPe4QykLhK7wHr%2BckAkm4mZfCtIp6wSiA3V1BMEdIABlN4Ildy7slEbbuqPRDghdm8T9d%2BBd%2B2kQJDvfDaPosrEyE97PXazfT7uY9R830OJTO7T63csPnvoadvgKfoopI7e1AU%3D&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20180301T062713Z&X-Amz-SignedHeaders=host&X-Amz-Expires=599&X-Amz-Credential=ASIAIS7S7GXU2E4EAFRQ%2F20180301%2Feu-central-1%2Fs3%2Faws4_request&X-Amz-Signature=ff74416096e16c6868e74c243a0be76e5d140ad4ed3efa393fcfa8d86ae59b5d'

我错过了什么吗?或者有没有其他方法可以使用命令行下载Lambda代码(如zip或普通代码)?

编辑(2018年3月6日):

有点不正统,我从命令行调用浏览器下载zip文件并睡眠直到文件下载。在我的Mac中,代码看起来像这样,

download_location=`jq -r '.Code.Location' lambda-config.json`

/usr/bin/open -a "/Applications/Google Chrome.app" "$download_location"

while [ ! -f $HOME/Downloads/LambdaFunctionName-*.zip ]
do
  sleep 2s
done

1 个答案:

答案 0 :(得分:1)

将curl输出保存到文件:

curl -o code.zip "<URL>"