You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用AWS CLI创建Lambda函数遇类型错误,GitHub Actions部署受阻求助

解决AWS Lambda创建函数时的路径与编码错误问题
  • 修正zip打包命令的路径分隔符
    GitHub Actions默认使用Ubuntu环境,路径分隔符是/而非Windows的\,你原命令里的.\helloWorld.js会被解析为异常路径,导致zip文件结构错误或为空。改成:

    zip -r helloWorld.zip ./helloWorld.js
    
  • 使用绝对路径指定zip文件
    AWS CLI的fileb://前缀需要精准指向文件位置,在GitHub Actions中,用环境变量${GITHUB_WORKSPACE}(当前工作目录的绝对路径)拼接路径,避免相对路径解析失败。修改后的创建命令:

    aws lambda create-function --function-name "helloWorld" --runtime nodejs20.x --role arn:aws:iam:... --handler "helloWorld.handler" --code fileb://${GITHUB_WORKSPACE}/helloWorld.zip
    
  • 验证zip文件完整性(可选但推荐)
    在执行创建命令前,添加检查步骤确认zip内容正确:

    unzip -l helloWorld.zip
    

    输出应显示包含helloWorld.js,且无多余目录层级(比如不要出现././helloWorld.js这类路径)。

错误原因说明

第一个'in <string>' requires string as left operand, not int错误,是路径解析异常导致AWS CLI读取文件时触发类型转换错误;换成file://后的编码错误,是因为zip属于二进制文件必须用fileb://前缀,但之前的路径问题让fileb://无法正确识别文件,才出现矛盾的报错。

内容的提问来源于stack exchange,提问作者Batku

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 08:56:11