I'm running a site built with laravel in a production environment.
I want to upload images using S3.
I can upload images without problems in my local environment.
An error occurred when using the production environment (ec2).
The following is an error message.
GuzzleHttp \ Exception \ ClientException
Client error: `GET http: // 169.254.169.254/latest/meta-data/iam/security-credentials /` resulted in a `404 Not Found` response:<? Xml version =" 1.0 "encoding =" iso-8859 -1 "?><! DOCTYPE html PUBLIC"-// W3C // DTD XHTML 1.0 Transitional // EN "" http: // www. (Truncated ...)
return new $className ($message, $request, $response, $previous, $ctx);
}
/ **
* Get a short summary of the response
*
* Will return `null` if the response is not printable.
*
* @param ResponseInterface $response
*
* @return string | null
Controller contents
use Storage;
--Omitted
public function create (Request $request)
{
$this->validate ($request, News :: $rules);
$news = new News;
$form = $request->all ();
if (isset ($form ['image'])) {
$path = Storage :: disk ('s3')->putFile ('/', $form ['image'],
'public');
$news->image_path = Storage :: disk ('s3')->url ($path);
} else {
$news->image_path = null;
}
unset ($form ['_ token']);
unset ($form ['image']);$news->fill ($form);
$news->save ();
return redirect ('news/create');
view contents
@extends ('layouts.news')
@section ('title', 'Create new news')
@section ('content')
Create new news
<form action = "{{action ('NewsController @ create')}}" method = "post" enctype = "multipart/form-data">
@if (count ($errors)>0)
<ul>
@foreach ($errors->all () as $e)
<li>{{$e}}</li>
@endforeach
</ul>
@endif
<label for = "title">Title</label>
<input type = "text" name = "title" value = "{{old ('title')}}">
<label for = "body">Body</label>
<textarea name = "body" rows = "20">{{old ('body')}}</textarea>
<label for = "title">Image</label>
<input type = "file" name = "image">
{{csrf_field ()}}
<input type = "submit" value = "update">
Back to TOP
</form>
@endsection
filesystems.php
's3' =>[
'driver' =>'s3',
'key' =>env ('AWS_ACCESS_KEY_ID'),
'secret' =>env ('AWS_SECRET_ACCESS_KEY'),
'region' =>env ('AWS_DEFAULT_REGION'),
'bucket' =>env ('AWS_BUCKET'),
],
.env
AWS_ACCESS_KEY_ID = ******************
AWS_SECRET_ACCESS_KEY = ***************
AWS_DEFAULT_REGION = ap-northeast-1
AWS_BUCKET = portfolio-salon
Turn off S3 bucket permissions (account, bucket).
ThinkingBecause the error was 404, I thought about a description mistake, but since I was going locally, I set it up for production
I think there is something wrong.
I'm sorry, please give me some advice.
Supplemental information (FW/tool version etc.)Laravel 6.2.0
PHP 7.2.19
cloud 9 (local environment)
ec2 (production environment)
-
Answer # 1
-
Answer # 2
Because it isGET http://169.254.169.254/latest/meta-data/iam/security-credentials
, it seems to be used for the behavior that it is not found when trying to acquire the credential information of EC2 instance.
How did you give permission to access S3 in the Cloud9 environment?
Do you give the necessary privileges to the production instance in some way?
Related articles
- php - i get an http error 500 error only in a production environment
- php - coding locally ⇒ upload to server ⇒ check with browser more efficient method
- php - when i try to upload an image to aws s3 from an app published on heroku, an error is displayed
- php - regarding the construction of laravel environment with docker, the installation was successful and the container was start
- i want to upload multiple images with django
- php - i want to upload an image using xfree
- php - file upload does not work when image size is large
- javascript - google map is not displayed in production environment
- php - images uploaded using move_uploaded_file cannot be saved
- i want to upload a web application created with php to a wordpress site and run it
- ruby - the production environment settings do not work
- i want to upload images with spring boot
- php - i want to save images using amazon s3 with the laravel app deployed on heroku
- wordpress copy from production environment to test environment
- php - about saving and displaying images in laravel
- java - how to create a war by reflecting the production environment information in the property file on the build server
- display images side by side in php
- i want to deploy a python file created on aws to a production environment
- php - a system that supports images of a specified size
- php - please tell me about the development environment for web applications
- [php_laravel] how to reflect session data in view file
- php - laravel 55 membership registration page is not displayed
- php - i get an error when submitting a laravel 5550 form
- php - laravel55 session_id is switched at post
- php - i want to install http_request2 of pear on ec2 of aws
- php - recursive function that makes the directory tree structure a flat file path
- php - non-root pages become not found in laravel nginx
- [php] how to convert from character string to date type
- i installed phpmyadmin on laravel homestead but can't access it
- php - vfs connection does not exist is displayed
Create an IAM role on the IAM management screen.
Type: EC2
Permission: Set access permission to S3 bucket or choose "Amazon S3 Full Access" from template
Next, when creating an instance on the EC2 management screen, select the IAM role created earlier.
For more information, try reading the related knowledge link below.
I have created an IAM role and want to assign it to an EC2 instance.
If you create an IAM role, you will be able to access it because the credentials are returned in curl http://169.254.169.254/latest/meta-data/iam/security-credentials/role_name.