无法上传 HelloWorldFunction 资源的 CodeUri 参数引用的工件 None

Bri*_*ian 9 amazon-s3 amazon-web-services aws-cloudformation serverless-application-model

我正在按照本教程学习如何使用SAM

这是我的代码:

模板.yml :

AWSTemplateFormatVersion : '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
  HelloWorldFunction:
    Type: AWS::Serverless::Function
    Properties:
      Handler: index.handler
      Runtime: nodejs8.10
Run Code Online (Sandbox Code Playgroud)

索引.js

exports.handler = async function(event, context) {
    return 'Hello World!';
};
Run Code Online (Sandbox Code Playgroud)

当我跑

sam package \
  --template-file template.yml \
  --output-template-file package.yml \
  --s3-bucket brian-test-sam
Run Code Online (Sandbox Code Playgroud)

我收到错误说 Unable to upload artifact None referenced by CodeUri parameter of HelloWorldFunction resource. An error occurred (AccessDenied) when calling the PutObject operation: Access Denied

为什么会发生这种情况?

我已经brian-test-sam在我的 AWS 账户上创建了 S3 存储桶。我已经检查过我的 IAM 用户是否有AmazonS3FullAccess权限。

命令

sam --debug package \                                                                                           <aws:dev-bionime>
  --template-file template.yml \
  --output-template-file package.yml \
  --s3-bucket brian-test-sam
Run Code Online (Sandbox Code Playgroud)

说错误是由 aws cloudformation package --output-template-file package.yml --s3-bucket brian-test-sam --template-file /path/to/my/files/helloworld/template.yml

我的 cloudformation 有什么问题?

我的 aws cli 版本是aws-cli/1.16.169 Python/3.7.3 Darwin/18.6.0 botocore/1.12.159. 而我的npm版本是6.10.1.

Omk*_*kar 8

即使我遇到了这个问题,我也采取了以下行动。

问题是由于 app.py 和 sam package 命令中的存储桶不匹配,因此更正了存储桶名称并再次运行“sam build”和“sam package”命令,它对我有用!

还要注意,如果您在运行“sam package”时遇到与时间相关的问题,那么应该是无效的系统时间,纠正它并再次运行“sam package”。


小智 6

我发现这个错误是因为我没有添加对运行构建的服务角色的 S3 访问权限

在角色的权限选项卡上,选择“附加策略”按钮并选择“AmazonS3FullAccess”,通过“附加策略”按钮附加它。

现在重新运行您的构建。


Pub*_*ana -1

您需要提供CodeUri指向本地目录的属性。

AWSTemplateFormatVersion : '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
  HelloWorldFunction:
    Type: AWS::Serverless::Function
    Properties:
      Handler: index.handler
      Runtime: nodejs8.10
      CodeUri: ./code
Run Code Online (Sandbox Code Playgroud)

  • 错误消息变为“无法上传 HelloWorldFunction 资源的 CodeUri 参数引用的工件 ./index.js”。当我将“CodeUri: ./index.js”添加到“template.yml”后,调用 PutObject 操作时发生错误(AccessDenied):Access Denied。 (4认同)