aws s3 php 연동 (s3 sdk)

AWS PHP SDK 설치하기

1. Composer 설치

  1. curl -sS https://getcomposer.org/installer | php

2. Composer를 통하여 AWS SDK PHP 설치

  1. php composer.phar require aws/aws-sdk-php

3. SDK 사용하기

  1. <?php
    require 'vendor/autoload.php';

 

credentials 설정하기

~/.aws/credentials 파일 수정

[default]
aws_access_key_id = YOUR_AWS_ACCESS_KEY_ID
aws_secret_access_key = YOUR_AWS_SECRET_ACCESS_KEY

[project1]
aws_access_key_id = ANOTHER_AWS_ACCESS_KEY_ID
aws_secret_access_key = ANOTHER_AWS_SECRET_ACCESS_KEY

aws_access_key_idaws_secret_access_key는 IAM에서 생성한 값이다.

https://console.aws.amazon.com/iam/home?region=ap-northeast-1#security_credential


Sample Code

git clone https://github.com/awslabs/aws-php-sample.git
curl -sS https://getcomposer.org/installer | php

php composer.phar install
php sample.php

 

 


Ref.