aws / aws-sdk-php-symfony

Apache License 2.0
350 stars 89 forks source link

Cache client credentials #62

Closed cjunge-work closed 4 years ago

cjunge-work commented 4 years ago

Please fill out the sections below to help us address your issue.

Version of AWS SDK for PHP?

aws/aws-sdk-php 3.133.26

Version of AWS Service Provider for Symfony?

aws/aws-sdk-php-symfony 1.3.0

Version of Symfony (bin/console --version in project dir)?

Symfony 3.4.38

Version of PHP (php -v)?

PHP 7.3.13

What issue did you see?

Unable to configure the cache for the client credentials

Steps to reproduce

N/A

Additional context

I'm trying to configure caching the client credentials using the DoctrineCacheAdaptor, but I am unable to get the cache to be used. All requests are still accessing the credentials each time the command is run.

(We swap credential providers on production, thus why we have 2 different configurations, but neither are using the cache.)

// config.yml
aws:
    version: latest
    region: ap-southeast-2
    credentials: "@aws_credentials"
    sqs:
        credentials: "@aws_cache_credentials"
//services.yml
    aws_cache_credentials:
        class: Aws\DoctrineCacheAdapter
        lazy:  true
        arguments:
            - "@doctrine_cache.providers.apcu"

    aws_credentials: aws_token_credentials
    aws_token_credentials:
        class: Aws\Credentials\Credentials
        lazy:  true
        arguments:
            - "%aws_credentials_key%"
            - "%aws_credentials_secret%"
    aws_instance_profile_credentials:
        class: Aws\Credentials\InstanceProfileProvider
        lazy:  true

The SQS Client is only using the default credentials, not the cache provider.

diehlaws commented 4 years ago

Hi @cjunge-work, thanks for reaching out and I do apologize for the long delay in our response on this.

Can you verify that php-apcu is installed on your machine and enabled in PHP? This can be done with php -i | grep apcu. If nothing comes up you'll want to install php-apcu then enable it with phpenmod apcu.

cjunge-work commented 4 years ago

@diehlaws Thank you for your response, and I think you've helped me find the problem!

$ php --ri apcu

apcu

APCu Support => Disabled
Version => 5.1.18
APCu Debugging => Disabled
MMAP Support => Enabled
MMAP File Mask =>  
Serialization Support => Disabled
Build Date => Mar 31 2020 02:30:28

Directive => Local Value => Master Value
apc.coredump_unmap => Off => Off
apc.enable_cli => Off => Off
apc.enabled => On => On
apc.entries_hint => 4096 => 4096
apc.gc_ttl => 3600 => 3600
apc.mmap_file_mask => no value => no value
apc.preload_path => no value => no value
apc.serializer => php => php
apc.shm_segments => 1 => 1
apc.shm_size => 32M => 32M
apc.slam_defense => Off => Off
apc.smart => 0 => 0
apc.ttl => 0 => 0
apc.use_request_time => On => On

It appears to be disabled via the CLI, which most of our async tasks are run via. Will get that changed & report back if it's fixed!

diehlaws commented 4 years ago

Hi @cjunge-work, have you had this behavior come up again since enabling php-apcu for php-cli?