October 22, 2024
Chicago 12, Melborne City, USA
PHP

AWS PHP SDK issue with credentials after upgrading to v3


I have an issue on getting credentials after upgrading from 2nd version to 3rd.

My service gets credentials from metadata server and cache them in file.

Here is how service definition looks like on 2nd version:

my_app.infrastructure.s3.client.credentials_cache.adapter:
        class: Doctrine\Common\Cache\FilesystemCache
        public: false
        arguments:
            - '%kernel.cache_dir%/aws_credentials'

my_app.infrastructure.s3.client.credentials_cache:
        class: Guzzle\Cache\DoctrineCacheAdapter
        public: false
        arguments:
            - '@my_app.infrastructure.s3.client.credentials_cache.adapter'

my_app.infrastructure.s3.client:
        class: Aws\S3\S3Client
        factory: [ 'Aws\S3\S3Client', 'factory' ]
        arguments:
            - region: "%my_app_organization_dictionary_aws_s3_region%"
              credentials.cache: '@my_app.infrastructure.s3.client.credentials_cache'

With that config it works for a while, after upgrading I changed a way how to cache credentials from metadata server.

    my_app.infrastructure.s3.client.credentials_cache.adapter:
        class: Doctrine\Common\Cache\FilesystemCache
        public: false
        arguments:
            - '%kernel.cache_dir%/aws_credentials'

    my_app.infrastructure.s3.client.credentials_cache:
        class: Aws\DoctrineCacheAdapter
        public: false
        arguments:
            - '@my_app.infrastructure.s3.client.credentials_cache.adapter'

    my_app.infrastructure.s3.client.credentials_provider:
        class: Aws\Credentials\CredentialProvider
        factory: [ 'Aws\Credentials\CredentialProvider', 'defaultProvider' ]
        public: false

    my_app.infrastructure.s3.client.cached_credentials_provider:
        class: Aws\Credentials\CredentialProvider
        factory: [ 'Aws\Credentials\CredentialProvider', 'cache' ]
        arguments:
            - '@my_app.infrastructure.s3.client.credentials_provider'
            - '@my_app.infrastructure.s3.client.credentials_cache'
        public: false

    my_app.infrastructure.s3.client:
        class: Aws\S3\S3Client
        factory: [ 'Aws\S3\S3Client', 'factory' ]
        arguments:
            - region: "%my_app_organization_dictionary_aws_s3_region%"
              version: 'latest'
              credentials: '@my_app.infrastructure.s3.client.cached_credentials_provider'

but still get an error

FAIL AWS S3: Fail check the AWS S3 with bucket "my_app_bucket". 
Reason: [Aws\Exception\CredentialsException] 
Error retrieving credentials from the instance profile metadata server. 
(cURL error 28: Operation timed out after 1001 milliseconds with 0 bytes received (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for http://169.254.169.254/latest/api/token).

Any ideas on what’s wrong with my setup?



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video