uam/aws-bundle

Symfony 扩展,提供 AWS S3 的包装服务

安装次数: 11,969

依赖者: 0

建议者: 0

安全: 0

星标: 2

关注者: 2

分支: 0

开放问题: 0

类型:symfony-bundle

0.5.1 2017-10-27 06:58 UTC

This package is auto-updated.

Last update: 2024-08-29 03:47:16 UTC


README

UAMAwsBundle 将 AWS 客户端作为服务暴露,以便在您的 Symfony 2 应用中使用。

安装

将包添加到项目的 composer.json

"require": {
	"uam/aws-bundle": "dev-master",
	…
}

在应用的 kernel 中注册此扩展

# app/AppKernel.php

public function registerBundles()
{
	bundles = (
		// …
		new UAM\Bundle\AwsBundle\UAMAwsBundle(),
	);

	return bundles();
}

配置

UAMAwsBundle 可以通过两种方式配置:提供 AWS 配置文件的路径或将配置参数设置在应用配置中。

直接配置

在应用配置中定义以下设置

# app/config/config.php
uam_aws:
	config:
		key: 	YOUR AWS ACCESS KEY
		secret: YOUR AWS SECRET KEY
		region: DEFAULT REGION

通过 AWS 配置文件

您还可以让应用配置文件指向您选择的 AWS 配置文件。此配置文件必须符合 AWS SDK 的 Aws::factory() 方法所需的格式。

# app/config/config.php
uam_aws:
	config_path: /path/to/aws/config/file

用法

目前此扩展定义了 2 个服务,提供 AWS S3 和 SQS 服务的客户端。

您可以通过容器以标准方式获取此服务,例如在控制器中

# MyBundle/Controller/MyController.php

public function someAction()
{
	$s3 = $this->container->get('uam_aws.s3');

	$sqs = $this->container->get('uam_aws.sqs');

	// ...
}

uam_aws.s3 服务是 Aws\S3\S3Client 的实例。请参阅 AWS SDK 文档了解 S3Client 的用法。

uam_aws.sqs 服务是 Aws\Sqs\SqsClient 的实例。请参阅 AWS SDK 文档了解 SQsClient 的用法。