Amazon web services 如何解决AWS Lamba函数部署问题?

Amazon web services 如何解决AWS Lamba函数部署问题?,amazon-web-services,deployment,aws-lambda,Amazon Web Services,Deployment,Aws Lambda,。。啊,又是我:) 这次有一个非常有趣的问题 同样,AWS Lambda函数、node.js 12、Javascript、Ubuntu 18.04用于本地开发、AWS cli/AWS sam/Docker/IntelliJ,所有这些都在本地运行良好,是时候部署了 所以我为测试设置了一个AWS帐户,创建并分配了一个访问密钥/密码,最后尝试部署 几乎在最后,一个错误弹出,中止部署 我正在从终端显示SAM cli版本,但IntelliJ也有同样的情况。 (当然,我会屏蔽/更改一些名称) 我将从一个终端

。。啊,又是我:) 这次有一个非常有趣的问题

同样,AWS Lambda函数、node.js 12、Javascript、Ubuntu 18.04用于本地开发、AWS cli/AWS sam/Docker/IntelliJ,所有这些都在本地运行良好,是时候部署了

所以我为测试设置了一个AWS帐户,创建并分配了一个访问密钥/密码,最后尝试部署

几乎在最后,一个错误弹出,中止部署

我正在从终端显示SAM cli版本,但IntelliJ也有同样的情况。 (当然,我会屏蔽/更改一些名称)

我将从一个终端出发,在那里我有我的本地沙箱和项目,然后:

$ sam deploy --guided

Configuring SAM deploy
======================

        Looking for config file [samconfig.toml] :  Not found

        Setting default arguments for 'sam deploy'
        =========================================
        Stack Name [sam-app]: MyActualProjectName
        AWS Region [us-east-1]: us-east-2
        #Shows you resources changes to be deployed and require a 'Y' to initiate deploy
        Confirm changes before deploy [y/N]: y
        #SAM needs permission to be able to create roles to connect to the resources in your template
        Allow SAM CLI IAM role creation [Y/n]: y
        Save arguments to configuration file [Y/n]: y
        SAM configuration file [samconfig.toml]: y
        SAM configuration environment [default]: 

        Looking for resources needed for deployment: Not found.
        Creating the required resources...
        Successfully created!

                Managed S3 bucket: aws-sam-cli-managed-default-samclisourcebucket-7qo1hy7mdu9z
                A different default S3 bucket can be set in samconfig.toml

        Saved arguments to config file
        Running 'sam deploy' for future deployments will use the parameters saved above.
        The above parameters can be changed by modifying samconfig.toml
        Learn more about samconfig.toml syntax at 
        https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-config.html
Error: Unable to upload artifact MyFunctionName referenced by CodeUri parameter of MyFunctionName resource.
ZIP does not support timestamps before 1980
$ 
我花了相当长的时间四处寻找这个问题,但我只找到了一些旧线程

理论上,这个问题在2018年得到了解决。。。但我不得不使用的一些npm库可能包含一些旧的。。。我到底是怎么修理这些东西的

在一个线程中,我找到了一种解决方法

在文件buildspec.yml中,有人建议在npm安装后添加:

ls$CODEBUILD\u SRC\u DIR 查找$CODEBUILD_SRC_DIR/node_modules-mtime+10950-exec touch{}

基本上,这个想法是在npm安装后触摸所有安装的文件,但仍然会发生错误

这是修改后的my buildspec.yml文件:

version: 0.2

phases:
  install:
    commands:
      # Install all dependencies (including dependencies for running tests)
      - npm install
      - ls $CODEBUILD_SRC_DIR
      - find $CODEBUILD_SRC_DIR/node_modules -mtime +10950 -exec touch {} ;
  pre_build:
    commands:
      # Discover and run unit tests in the '__tests__' directory
      - npm run test
      # Remove all unit tests to reduce the size of the package that will be ultimately uploaded to Lambda
      - rm -rf ./__tests__
      # Remove all dependencies not needed for the Lambda deployment package (the packages from devDependencies in package.json)
      - npm prune --production
  build:
    commands:
      # Use AWS SAM to package the application by using AWS CloudFormation
      - aws cloudformation package --template template.yml --s3-bucket $S3_BUCKET --output-template template-export.yml
artifacts:
  type: zip
  files:
    - template-export.yml
我会继续搜索,但我想知道这里是否有人遇到过此类问题,以及如何解决此类问题的一些建议/方法

非常感谢


Steve

您是否验证了
touch
命令实际上更新了所有30多年前的文件?好像没有。或者尝试建议的package.json解决方法,然后重新运行
npm install
。我确实验证了语法,但实际上缺少正确的命令结尾,无法关闭-exec命令。现在是:查找$CODEBUILD_SRC_DIR/node_modules-mtime+10950-exec touch{}';'但仍然不起作用。我想知道我是否没有正确设置$CODEBUILD\u SRC\u DIR,因为我甚至没有在日志中看到ls输出。。。感谢您,为什么不直接进入项目的根文件夹并使用
find-mtime+10950是否查找所有旧文件?使用(正确的)触摸选项重新运行,或者如果没有太多文件,只需手动运行即可。我想不出有什么合法的理由可以使用2000年或更早的文件。我通常更喜欢专门针对某个区域,而不是空白所有内容。但是,是的,如果我不能更快地找到构建区域所在的位置(我怀疑构建过程在某处创建了一个临时目录),我可能会尝试触摸所有内容。当然,假设临时建筑目录是在本地项目空间中创建的。感谢IntelliJ,我能够部署它,只是告诉它在docker中构建,而不是从系统中构建。我想知道这个问题是否与Ubuntu有关。稍后我将尝试在Mac而不是Linux上设置开发环境,看看是否仍然存在相同的问题。。。非常讨厌追鬼:)