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

Signed url not working #7417

Closed
1 task done
MakarandPundlik opened this issue Jan 3, 2023 · 3 comments
Closed
1 task done

Signed url not working #7417

MakarandPundlik opened this issue Jan 3, 2023 · 3 comments
Assignees
Labels
aws:s3 Amazon Simple Storage Service type: usage Usage of LocalStack and Best Practices

Comments

@MakarandPundlik
Copy link

MakarandPundlik commented Jan 3, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

I am generating signed url with nodeJs using this piece of code

const params = {
                    Bucket: "my-bucket",
                    Key: some path,
                    Expires: 3600,
                    ServerSideEncryption: 'aws:kms',
                    SSEKMSKeyId: EncryptionKey,
                    ACL: 'bucket-owner-full-control'
}

const getURL = (data, params) => {
        return new Promise(function (resolve) {
            s3 = new AWS.S3({
                accessKeyId: "test",
                secretAccessKey:"test",
                endpoint: "http://localstack:4566",
                region: "us-east-1",
                s3ForcePathStyle: true,
                signatureVersion: 'v4'
            });
            s3.getSignedUrl('putObject', params, function (err, url) {
                if (url) {
                    const c = {
                      //some assignment operation
                    };
                    return resolve(c);
                } else {
                    logEvent = {
                        statusCode: 500,
                        body: "Internal server error: error while getting a 'Signed URL'"
                    };
                    resolve(logEvent);
                }
            });
        })

    }

After invoking this function i'm getting a signed url .
When I use POSTMAN to upload the data using PUT request it returns nothing
image
When I change localstack to localhost it gives me nothing but a blank response with statusCode 200
This is my docker compose file

version: "2.1"

services:
  localstack:
    image: "localstack/localstack"
    container_name: "localstack"
    ports:
      - "4566-4620:4566-4620"
      - "127.0.0.1:8055:8080"
    environment:
      - SERVICES=s3,es,dynamodb,apigateway,lambda,sns,sqs,cloudformation
      - DEBUG=1
      - EDGE_PORT=4566
      - DATA_DIR=/var/lib/localstack/data
      - DOCKER_HOST=unix:///var/run/docker.sock
      - HOST_TMP_FOLDER=${TMPDIR}
      - LAMBDA_EXECUTOR=docker-reuse 
      - DYNAMODB_SHARE_DB=1
      - DISABLE_CORS_CHECKS=1
    

    volumes:
      - "${TMPDIR:-/var/lib/localstack}:/var/lib/localstack"
      - "/var/run/docker.sock:/var/run/docker.sock"
    networks:
      - "local"
networks:
  local:
    driver: "bridge"

Where am I going wrong?

Expected Behavior

Should be able to upload files to the s3 bucket.

How are you starting LocalStack?

With a docker-compose file

Steps To Reproduce

How are you starting localstack (e.g., bin/localstack command, arguments, or docker-compose.yml)

docker run localstack/localstack

Client commands (e.g., AWS SDK code snippet, or sequence of "awslocal" commands)

awslocal s3 mb s3://mybucket

Environment

- OS: Windows 11
- LocalStack: 1.3.0

Anything else?

To refer s3 bucket within the localstack endpoint used is http://localstack:4566. How do I access it from outside the localstack?

@MakarandPundlik MakarandPundlik added status: triage needed Requires evaluation by maintainers type: bug Bug report labels Jan 3, 2023
@steffyP steffyP added the aws:s3 Amazon Simple Storage Service label Jan 3, 2023
@bentsku bentsku self-assigned this Jan 3, 2023
@bentsku
Copy link
Contributor

bentsku commented Jan 4, 2023

Hi @MakarandPundlik,

Concerning the endpoint of S3, it depends from where you are trying to access LocalStack, depending on your setup.
From your host, you can access LocalStack at localhost:4566 or localhost.localstack.cloud:4566. In the case of s3 clients, you can use a specific endpoint: s3.localhost.localstack.cloud:4566.
From inside Docker containers on the same network as LocalStack, it will use the service name by default.

Circling back to the pre-signed URL issue: what exactly is the issue? Have you try to check if the object is in your bucket?

From the AWS documentation, a PutObject request returns an empty 200 response when successful, with headers.

So it seems your request is actually successful. Can you confirm? Thanks!

@bentsku bentsku added type: usage Usage of LocalStack and Best Practices status: response required Waiting for a response from the reporter and removed type: bug Bug report status: triage needed Requires evaluation by maintainers labels Jan 4, 2023
@MakarandPundlik
Copy link
Author

Hi @MakarandPundlik,

Concerning the endpoint of S3, it depends from where you are trying to access LocalStack, depending on your setup. From your host, you can access LocalStack at localhost:4566 or localhost.localstack.cloud:4566. In the case of s3 clients, you can use a specific endpoint: s3.localhost.localstack.cloud:4566. From inside Docker containers on the same network as LocalStack, it will use the service name by default.

Circling back to the pre-signed URL issue: what exactly is the issue? Have you try to check if the object is in your bucket?

From the AWS documentation, a PutObject request returns an empty 200 response when successful, with headers.

So it seems your request is actually successful. Can you confirm? Thanks!

Hi @bentsku , actually it depends upon where do you access it from.
If file has to be uploaded from inside the docker, url should not be modified.
But if file is to be uploaded form POSTMAN or anything that not a part of docker container, same URL should be modified to localhost instead of localstack
Issue has been resolved now.
I have created many issues on localstack forum and github, I will be creating POC about Serverless lambdas + dynamodb + elasticsearch + s3 + KMS and SQS with nodeJs in Localstack
I would like to thank team members of Localstack for their support and guidance.

Closing this issue as well.

@bentsku bentsku removed the status: response required Waiting for a response from the reporter label Jan 5, 2023
@bentsku
Copy link
Contributor

bentsku commented Jan 5, 2023

I'm glad your issue is resolved, and thank you for the feedback! And don't hesitate to post your POC on our community Slack!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aws:s3 Amazon Simple Storage Service type: usage Usage of LocalStack and Best Practices
Projects
None yet
Development

No branches or pull requests

3 participants