Announcing Our Best Sale EVER!

Hurry quick because these deals won't last long. Use code BF20 at checkout.

50% OFF November 20 - November 27

30% OFF November 28 - December 1

10% OFF December 2 - December 4

If you need to use instance profiles and IAM Roles to send Gravity Forms file uploads to an Amazon S3 bucket, SyncS3 for Gravity Forms includes a filter for overwriting the S3 client object. This will allow you to assume an IAM user role, and configure the S3 client to use that role’s credentials to upload files.

Using Amazon’s sample code in Assuming IAM Roles in another AWS account, we’ll adapt it to work with SyncS3. Note that some of this code needs modified to use your own AWS credentials.

add_filter( 'syncs3_s3_client', 'my_iam_syncs3_s3_client', 10, 3 );
/**
 * Overwrites the S3 client to use an IAM user's credentials.
 * @see https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/guide_credentials_assume_role.html#assuming-an-iam-role-in-another-aws-account
 *
 * @param  object   $client     S3Client
 * @param  array    $config     Default configuration data
 * @param  mixed    $entry      Entry data aray, if available, else empty
 *
 * @return object S3Client
 */
function my_iam_syncs3_s3_client( $client, $config, $entry ) {
	
	SyncS3::autoload();

	// This needs modified to fit your account
	$stsClient = new Aws\Sts\StsClient([
		'profile' => 'default',
		'region' => 'us-east-2',
		'version' => '2011-06-15'
	]);

	// This needs modified to fit your account
	$result = $stsClient->AssumeRole( array(
		'RoleArn' => 'arn:aws:iam::123456789012:role/xaccounts3access',
		'RoleSessionName' => 's3-access-example',
	) );

	// Create the new S3 client using the IAM user
	 $client = new Aws\S3\S3Client([
		'region' => $config['region'],
		'credentials' => array(
			'key'    => $result['Credentials']['AccessKeyId'],
			'secret' => $result['Credentials']['SecretAccessKey'],
			'token'  => $result['Credentials']['SessionToken']
		)
	]);
	
	return $client;
}

0 Comments

Leave a Reply

Your Cart
Your cart is currently empty.
Open Cart

How do you build WordPress websites?

Are you into using page builders to create websites and earn income? That's what we love doing, too! That's why we build extensions for the most popular WordPress page builders - to help you build awesome websites and make more money.

If you enjoy the same things, we'd love to have you as part of the Elegant Modules community. Let's get to know each other!

Interests

Welcome! We're so excited to get to meet you, and look forward to chatting with you soon.