in Education by
I'm trying to set up an Amazon Linux AMI(ami-f0091d91) and have a script that runs a copy command to copy from an S3 bucket. aws --debug s3 cp s3://aws-codedeploy-us-west-2/latest/codedeploy-agent.noarch.rpm. This script works perfectly on my local machine but fails with the following error on the Amazon Image: 2016-03-22 01:07:47,110 - MainThread - botocore.auth - DEBUG - StringToSign: HEAD Tue, 22 Mar 2016 01:07:47 GMT x-amz-security-token:AQoDYXdzEPr//////////wEa4ANtcDKVDItVq8Z5OKms8wpQ3MS4dxLtxVq6Om1aWDhLmZhL2zdqiasNBV4nQtVqwyPsRVyxl1Urq1BBCnZzDdl4blSklm6dvu+3efjwjhudk7AKaCEHWlTd/VR3cksSNMFTcI9aIUUwzGW8lD9y8MVpKzDkpxzNB7ZJbr9HQNu8uF/st0f45+ABLm8X4FsBPCl2I3wKqvwV/s2VioP/tJf7RGQK3FC079oxw3mOid5sEi28o0Qp4h/Vy9xEHQ28YQNHXOBafHi0vt7vZpOtOfCJBzXvKbk4zRXbLMamnWVe3V0dArncbNEgL1aAi1ooSQ8+Xps8ufFnqDp7HsquAj50p459XnPedv90uFFd6YnwiVkng9nNTAF+2Jo73+eKTt955Us25Chxvk72nAQsAZlt6NpfR+fF/Qs7jjMGSF6ucjkKbm0x5aCqCw6YknsoE1Rtn8Qz9tFxTmUzyCTNd7uRaxbswm7oHOdsM/Q69otjzqSIztlwgUh2M53LzgChQYx5RjYlrjcyAolRguJjpSq3LwZ5NEacm/W17bDOdaZL3y1977rSJrCxb7lmnHCOER5W0tsF9+XUGW1LMX69EWgFYdn5QNqFk6mcJsZWrR9dkehaQwjLPcv/29QcM+b5u/0goazCtwU= /aws-codedeploy-us-west-2/latest/codedeploy-agent.noarch.rpm 2016-03-22 01:07:47,111 - MainThread - botocore.endpoint - DEBUG - Sending http request: 2016-03-22 01:07:47,111 - MainThread - botocore.vendored.requests.packages.urllib3.connectionpool - INFO - Starting new HTTPS connection (1): aws-codedeploy-us-west-2.s3.amazonaws.com 2016-03-22 01:07:47,151 - MainThread - botocore.vendored.requests.packages.urllib3.connectionpool - DEBUG - "HEAD /latest/codedeploy-agent.noarch.rpm HTTP/1.1" 403 0 2016-03-22 01:07:47,151 - MainThread - botocore.parsers - DEBUG - Response headers: {'x-amz-id-2': '0mRvGge9ugu+KKyDmROm4jcTa1hAnA5Ax8vUlkKZXoJ//HVJAKxbpFHvOGaqiECa4sgon2F1kXw=', 'server': 'AmazonS3', 'transfer-encoding': 'chunked', 'x-amz-request-id': '6204CD88E880E5DD', 'date': 'Tue, 22 Mar 2016 01:07:46 GMT', 'content-type': 'application/xml'} 2016-03-22 01:07:47,152 - MainThread - botocore.parsers - DEBUG - Response body: 2016-03-22 01:07:47,152 - MainThread - botocore.hooks - DEBUG - Event needs-retry.s3.HeadObject: calling handler 2016-03-22 01:07:47,152 - MainThread - botocore.retryhandler - DEBUG - No retry needed. 2016-03-22 01:07:47,152 - MainThread - botocore.hooks - DEBUG - Event after-call.s3.HeadObject: calling handler 2016-03-22 01:07:47,152 - MainThread - botocore.hooks - DEBUG - Event after-call.s3.HeadObject: calling handler 2016-03-22 01:07:47,152 - MainThread - awscli.errorhandler - DEBUG - HTTP Response Code: 403 2016-03-22 01:07:47,152 - MainThread - awscli.customizations.s3.s3handler - DEBUG - Exception caught during task execution: A client error (403) occurred when calling the HeadObject operation: Forbidden Traceback (most recent call last): File "/usr/local/lib/python2.7/site-packages/awscli/customizations/s3/s3handler.py", line 100, in call total_files, total_parts = self._enqueue_tasks(files) File "/usr/local/lib/python2.7/site-packages/awscli/customizations/s3/s3handler.py", line 178, in _enqueue_tasks for filename in files: File "/usr/local/lib/python2.7/site-packages/awscli/customizations/s3/fileinfobuilder.py", line 31, in call for file_base in files: File "/usr/local/lib/python2.7/site-packages/awscli/customizations/s3/filegenerator.py", line 142, in call for src_path, extra_information in file_iterator: File "/usr/local/lib/python2.7/site-packages/awscli/customizations/s3/filegenerator.py", line 314, in list_objects yield self._list_single_object(s3_path) File "/usr/local/lib/python2.7/site-packages/awscli/customizations/s3/filegenerator.py", line 343, in _list_single_object response = self._client.head_object(**params) File "/usr/local/lib/python2.7/site-packages/botocore/client.py", line 228, in _api_call return self._make_api_call(operation_name, kwargs) File "/usr/local/lib/python2.7/site-packages/botocore/client.py", line 488, in _make_api_call model=operation_model, context=request_context File "/usr/local/lib/python2.7/site-packages/botocore/hooks.py", line 226, in emit return self._emit(event_name, kwargs) File "/usr/local/lib/python2.7/site-packages/botocore/hooks.py", line 209, in _emit response = handler(**kwargs) File "/usr/local/lib/python2.7/site-packages/awscli/errorhandler.py", line 70, in __call__ http_status_code=http_response.status_code) ClientError: A client error (403) occurred when calling the HeadObject operation: Forbidden 2016-03-22 01:07:47,153 - Thread-1 - awscli.customizations.s3.executor - DEBUG - Received print task: PrintTask(message='A client error (403) occurred when calling the HeadObject operation: Forbidden', error=True, total_parts=None, warning=None) A client error (403) occurred when calling the HeadObject operation: Forbidden However, when I run it with the --no-sign-request option, it works perfectly: aws --debug --no-sign-request s3 cp s3://aws-codedeploy-us-west-2/latest/codedeploy-agent.noarch.rpm . Can someone please explain what is going on? Select the correct answer from above options

1 Answer

0 votes
by
 
Best answer
First, check whether your attached policy provides complete access to S3 and also to access objects within a S3 bucket, you have to provide this in the policy: “Resource”:"arn:aws:s3:::BUCKET_NAME/*" Rather than this, "Resource": "arn:aws:s3:::BUCKET_NAME" The first statement allows complete access to all the objects available in the given S3 bucket. If this is not the problem, then check whether the EC2 instances and the buckets are in the same regions. If they are not in the same regions, then it will raise errors. So, make sure EC2 instances and the buckets are in the same regions.

Related questions

0 votes
    Is it possible to get the ARN of an S3 bucket via the AWS command line? I have looked through the documentation ... way to do this. Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    I'm starting a bash script which will take a path in S3 (as specified to the ls command) and dump the ... finding which does it? Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    I'm having trouble using * in the AWS CLI to select a subset of files from a certain bucket. Adding * to the ... s3://data/2016-08*. Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    I am using the aws cli to list the files in an s3 bucket using the following command (documentation): aws s3 ... only the file list? Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    I am trying out a simple example suggested by AWS documentation to create a role using a policy json file http:// ... botocore/1.3.9 Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    I created a new Access Key and configured that in the AWS CLI with aws configure. It created the .ini file in ~/ ... . How to fix this? Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    I am thinking about redeploying my static website to Amazon S3. I need to automate the deployment so I was looking ... and AWS CLI? Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    I have a use case where I programmatically bring up an EC2 instance, copy and executable file from S3, run it and ... using the CLI ? Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I tried to follow this tutorial. This is what I did in the console: pip3 install --user --upgrade awscli after ... 's the problem here? Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    Looking for a quick way to pull my account number, I had originally thought of using aws iam get-account- ... cross-account origins? Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    I am following the AWS CLI Setup guide. I have managed to successfully install the tool on my Mac OS X ... could be going wrong? Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    I am trying to use aws container service as per the documentation in http://docs.aws.amazon.com/AmazonECS/latest/ ... in a console? Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    I'm trying to deploy a Docker container image to AWS using ECS, but the EC2 instance is not being created. I have ... , to begin with!! Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    Are there use cases that lend themselves better to Amazon cloudfront over s3 or the other way around? I'm ... 2 through examples. Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
0 votes
    Can someone please tell me how can I get the ARN for an S3 bucket using AWS Cli Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
...