0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[PHP][Laravel]SQSにキューデータを送る

0
Last updated at Posted at 2019-03-15

はじめに

取り急ぎ、期待した挙動の確認が取れたコードだけでも共有しておきます。
書き留めレベルですが、参考にしてもらえると嬉しいです。

事前に

composerでSDKをインストール

$ composer require aws/aws-sdk-php

今回のコード

<?php
require 'vendor/autoload.php'; //autoload.php参照
use Aws\Sqs\SqsClient;
use Aws\Exception\AwsException;
define('QUEUE_URL', 'https://sqs.ap-northeast-1.amazonaws.com/0000000/XXXXXXX'); //ここにURL

try{
    $config = [
        'credentials' => [ //アクセスキーとシークレットキーは一つの配列にまとめる必要がある。
            'key' => 'XXXXXXXXXXXXXX', //ここにアクセスキー
            'secret' => 'XXXXXXXXXXXXXX', //ここにシークレットキー
        ],
        'region' => 'ap-northeast-1', //ここにリージョン    
        'version' => 'latest',
    ];
    //SqsClientオブジェクトを作成 ここに送りたいものを入れる
    $client = SqsClient::factory($config);
    $params = [
        'DelaySeconds' => 0,
        'MessageAttributes' => [
            'Title' => [
                'DataType' => 'String',
                'StringValue' => 'Amazon SQS Test',
            ],
        ],
        'MessageBody' => 'This is Amazon SQS Test',
        'QueueUrl' => QUEUE_URL, //上で定数にしたURLね
    ];
    $result = $client->sendMessage($params);

    var_dump($result); //結果確認用

} catch(AwsException $e){ //いつものエラー処理
    var_dump($e->getMessage());
}

アクセスキーとシークレットキー(認証情報やcredential情報とも呼ばれている)の取得方法はこちらをご参照ください。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?