Unable to upload artifact None referenced by CodeUri parameter of HelloWorldFunction resource

Brian picture Brian · Jul 19, 2019 · Viewed 13.9k times · Source

I'm following this tutorial to learn how to use SAM.

Here's the code I have:

template.yml:

AWSTemplateFormatVersion : '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
  HelloWorldFunction:
    Type: AWS::Serverless::Function
    Properties:
      Handler: index.handler
      Runtime: nodejs8.10

index.js

exports.handler = async function(event, context) {
    return 'Hello World!';
};

When I run

sam package \
  --template-file template.yml \
  --output-template-file package.yml \
  --s3-bucket brian-test-sam

I got the error saying Unable to upload artifact None referenced by CodeUri parameter of HelloWorldFunction resource. An error occurred (AccessDenied) when calling the PutObject operation: Access Denied

Why does this happen?

I've created the S3 bucket brian-test-sam on my AWS account. I've checked that my IAM user has AmazonS3FullAccess permission.

The command

sam --debug package \                                                                                           <aws:dev-bionime>
  --template-file template.yml \
  --output-template-file package.yml \
  --s3-bucket brian-test-sam

says that the error was generated by aws cloudformation package --output-template-file package.yml --s3-bucket brian-test-sam --template-file /path/to/my/files/helloworld/template.yml

What is wrong with my cloudformation?

My aws cli version is aws-cli/1.16.169 Python/3.7.3 Darwin/18.6.0 botocore/1.12.159. And my npm version is 6.10.1.

Answer

Omkar picture Omkar · Aug 13, 2019

Even I faced this issue, I took following action.

Issue was due to mismatch of bucket in app.py and in sam package command, so corrected bucket name and run the "sam build" and "sam package" commands again, it worked for me !

One more care, If you face time related issue while running "sam package", then there should be invalid system time, get it corrected and run "sam package" again.