Skip to content

Issues with Amplify JS and LocalStack: Authentication and S3 Endpoint Problems

0

Hello,

I am seeking help with a legacy application that has been working well in production. The backend is built using AWS CDK, and the frontend is an AWS Amplify application (client code only).

I have successfully deployed my CDK code to LocalStack. However, I need to redirect AWS Amplify to use this new LocalStack instance.

I can log in via Cognito by overriding the endpoint parameter in the auth configuration. However, any attempt to override the S3 endpoint fails.

I have looked into amplify-localstack, but this seems to be for deploying Amplify backend resources and does not clearly explain how to use it for my scenario.

{
      API: {
        endpoints: [
          {
            custom_header: async () => {
              return {
                Authorization: `${(await Auth.currentSession())
                  .getAccessToken()
                  .getJwtToken()}`,
              };
            },
            endpoint: "http://localhost:4566/restapis/ega9w41v7i/dev",
            name: "ormAPI",
          },
        ],
      },
      Auth: {
        authenticationFlowType: "USER_SRP_AUTH",
        endpoint: "http://localhost:4566", // Ensure this points to LocalStack
        identityPoolId: "ap-southeast-2:c87d86a1-0d0f-40ea-abc1-f4d437f075cb",
        region: "ap-southeast-2",
        userPoolId: "ap-southeast-2_eeaab13dc3824e8ebfe6206ec5fa9728",
        userPoolWebClientId: "cmx792rwg9pdup60pb4i9me2yf",
      },
      Storage: {
        AWSS3: {
          bucket: "storagestack-dev-databucketd8691f4e-7096f617",
          endpoint: "http://localhost:4566",
          region: "ap-southeast-2",
          s3ForcePathStyle: true, // Suggested by ChatGPT
        },
      },
      endpoint: "http://localhost:4566",
    };
  }

Does anyone have any advice or examples on how to properly configure Amplify to use LocalStack for S3?

Thank you!

S3 Endpoint in network tab

Cognito Endpoint in network tab

1 Answer
0

Have you looked into: https://docs.localstack.cloud/user-guide/aws/s3/ ?

  • Ensure that the Localstack endpoint http://localhost:4566 is accessible and responding. You can test by navigating to http://localhost:4566/health to see if Localstack services are up.

  • Make sure the bucket storagestack-dev-databucketd8691f4e-7096f617 exists in Localstack.

EXPERT
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.