#AWS S3 + Instance Profile + config:cache?

1 messages · Page 1 of 1 (latest)

silent meteor
#

Hi,

I'm trying to deploy to production at AWS EC2. In accordance with the AWS best practices, the instance should have an associated IAM role with the required permissions rather than credentials themselves. We're trying to follow that practice here.

The problem is that with the following configuration:

        'upload_s3' => [
            'driver' => 's3',
            'credentials' => [
                'key' => '',
                'secret' => '',
                'provider' => CredentialProvider::memoize(
                    CredentialProvider::instanceProfile(),
                ),
            ],
            'region' => env('AWS_DEFAULT_REGION'),
            'bucket' => env('UPLOAD_BUCKET'),
            'url' => env('AWS_URL'),
            'endpoint' => env('AWS_ENDPOINT'),
            'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false),
            'throw' => true,
        ],

The code is working as expected, but php artisan config:cache is failing with an error:

  Your configuration files are not serializable.
  // in a trace, there's a mention of some closure

The configuration is pretty big and complex, so caching the config is a must.

I've checked the FilesystemManager::createS3Driver code, it is completely not customizable. The only solution is to roll in a custom S3 driver provider that will inject the instance profile credential provider.
That solution doesn't look good, so I wanted to ask if there are any other workarounds?

Thank you.

P. S. There's a relevant issue at GH: https://github.com/aws/aws-sdk-php/issues/2290 - but it is old and dead, so I thought to ask first.

GitHub

Confirm by changing [ ] to [x] below: I've gone though Developer Guide and API reference I've checked AWS Forums and StackOverflow for answers Version of AWS SDK for PHP? 3.163.3 Version of...

frank spindle
#

So what exactly are you trying to do here? Load the .aws.credentials file? If so, afaik the SDK will already do that for you, if set up properly
Laravel simply can't cache some values in the config, so what you're trying to do probably won't be cacheable

silent meteor