如何解决AWS Lamba功能部署问题?

时间:2020-10-28 22:51:29

标签: amazon-web-services deployment aws-lambda

.. aaa和我再次:) 这次有一个非常有趣的问题。

再次使用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 install之后添加:

ls $ CODEBUILD_SRC_DIR 找到$ CODEBUILD_SRC_DIR / node_modules -mtime +10950 -exec touch {};

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

这是修改后的我的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

我将继续搜索,但是我再次想知道这里是否有人遇到这种问题,因此提出了一些有关如何解决该问题的建议/方法。

非常感谢!

史蒂夫

0 个答案:

没有答案