Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

S3 putObject + localstack = Could not contact remote server #1325

Open
dudekm opened this issue Nov 8, 2022 · 6 comments
Open

S3 putObject + localstack = Could not contact remote server #1325

dudekm opened this issue Nov 8, 2022 · 6 comments

Comments

@dudekm
Copy link

dudekm commented Nov 8, 2022

Hi.
I'm using async-aws with localstack to mock requests and I have a problem with putObject. Here you can find my PHP and JavaScript code to check if it works -> https://gist.github.com/dudekm/807f94dcc37a51adf43ec9e8b3652238

PHP + ASYNC-AWS + localstack - doens't work
I can list buckets and files - everything works perfectly. Logs from localstack:
localstack_demo | 2022-11-08T06:54:51.842 INFO --- [ asgi_gw_0] localstack.services.infra : Starting mock S3 service on http port 4566 ... localstack_demo | 2022-11-08T06:58:24.996 INFO --- [ asgi_gw_0] localstack.request.aws : AWS s3.ListBuckets => 200 localstack_demo | 2022-11-08T06:58:25.008 INFO --- [ asgi_gw_0] localstack.request.aws : AWS s3.ListObjectsV2 => 200

But when I want to use putObject, it's not possible because of "Could not contact remote server" and in localstack I can't see any request related to putObject.

JavaScript + AWS SDK + localstack - works
I decided to test if JavaScript aws-sdk will work. The upload works perfectly.

localstack_demo | 2022-11-08T06:58:22.476 INFO --- [ asgi_gw_0] localstack.request.aws : AWS s3.PutObject => 200

For sure it's not a problem with localstack (for JS sdk everything is fine). So, looks like async-aws has a bug or my config for async-aws is not correct. But, is it possible that config is not correct only for putObject???

@jderusse
Copy link
Member

jderusse commented Nov 8, 2022

@dudekm dudekm changed the title S3 putObject + localstack + Could not contact remote server S3 putObject + localstack = Could not contact remote server Nov 8, 2022
@dudekm
Copy link
Author

dudekm commented Nov 8, 2022

Did you tried: https://async-aws.com/clients/s3.html#non-aws-s3-endpoints ?

Yes. But one interesting thing. I tried to use two hosts: localhost and 127.0.01.

Here is my first config:
endpoint -> localhost:4566, without pathStyleEndpoint

$s3 = new S3Client([
    'accessKeyId' => 'access-key',
    'accessKeySecret' => 'secret-key',
    'region' => 'region-key',
    'endpoint' => 'http://localhost:4566',
]);

it's possible to get a list of buckets but it wasn't possible to get a file list (listObjectsV2 -> Could not contact remote server.)

but when I changed the endpoint to http://127.0.0.1:4566

$s3 = new S3Client([
    'accessKeyId' => 'access-key',
    'accessKeySecret' => 'secret-key',
    'region' => 'region-key',
    'endpoint' => 'http://127.0.0.1:4566',
]);

I can get a list of files.

So, I decided to add mentioned option pathStyleEndpoint to localhost:4566 endpoint

$s3 = new S3Client([
    'accessKeyId' => 'access-key',
    'accessKeySecret' => 'secret-key',
    'region' => 'region-key',
    'pathStyleEndpoint' => true,
    'endpoint' => 'http://localhost:4566',
]);

and I can use localhost:4566 and can see a list of files.

so maybe something is wrong with the endpoint for putObject?

@dudekm
Copy link
Author

dudekm commented Nov 8, 2022

When I'm using aws sdk (https://github.com/aws/aws-sdk-php) everything is ok.
Here you have code

https://gist.github.com/dudekm/e4ec6600f34fd50dac0622903034a09e

so, probably problem is inside async-aws :(

@jderusse
Copy link
Member

jderusse commented Nov 8, 2022

Thanks for the reproducer.

I tried to start the stack on my local machine, but I'm not able to make it work. Local stack stuck even when using aws-cli.

I replaced local stack by another S3 like service (I used docker run -d -p 4566:4569 --name async_aws_s3-client asyncaws/testing-s3) and your code worked out of the box.

If you want, you can add a logger to get more information about the requests performed by AsyncAws:

use Symfony\Component\Console\Logger\ConsoleLogger;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Output\OutputInterface;

include(__DIR__.'/vendor/autoload.php');

$logger = new ConsoleLogger(new ConsoleOutput(OutputInterface::VERBOSITY_VERY_VERBOSE));
// Instantiate an Amazon S3 client.
$s3 = new S3Client([
    'endpoint' => 'http://localhost:4569',
    'pathStyleEndpoint' => true,
], new NullProvider(), null, $logger);

@dudekm
Copy link
Author

dudekm commented Nov 8, 2022

Current code and result https://gist.github.com/dudekm/ccb06aafb7e2309497fe63cd571c08c3

Doesn't matter if endpoint is localhost:4566 or 127.0.0.1:4566.
Try #1 after 900ms: Idle timeout reached for "http://localhost:4566/demo-bucket/new-key-file".
Try #1 after 900ms: Idle timeout reached for "http://127.0.0.1:4566/demo-bucket/new-key-file".

Did you try running the code from my first post? BEcause this one is related to async-aws. The second is for aws-php-sdk.

I will try to prepare a repository with docker, nginx, php, localstack, and my php code. The environment will be the same for everyone, and we can test php code.

@gndk
Copy link

gndk commented Jan 10, 2023

I ran into the same issue, but with SQS. Gave up after hours of banging my head against the wall, trying all possible combinations of configurations. Both localstack and asyncaws/testing-sqs did not work for me with fullstack Symfony (Messenger + sqs-messenger + async-aws + async-aws/symfony-bundle). Connection with aws cli works fine, but with async-aws it does not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants