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

UnknownEndpoint: Inaccessible host: localhost'. This service may not be available in the us-east-1' region. #116

Open
Nicoxys opened this issue Dec 22, 2020 · 4 comments

Comments

@Nicoxys
Copy link

Nicoxys commented Dec 22, 2020

Hi!

I state that I am only doing some simple tests to see if all this is for me. First, an example.

serverless.yml:

service: local-serverless

plugins:
  - serverless-s3-local
  - serverless-plugin-typescript
  - serverless-offline

provider:
  name: aws
  runtime: nodejs12.x
  stage: v1
  apiGateway:
    shouldStartNameWithService: true
  httpApi:
    cors: true
  environment:
    keysBucket: ${self:custom.keysBucket}
  iamRoleStatements:
    - Effect: "Allow"
      Action:
        - "s3:GetObject"
      Resource:
        Fn::Join:
          - ""
          - - "arn:aws:s3:::"
            - Ref: ${self:custom.keysBucket}

functions:
  hello:
    handler: src/hello.handler
    events:
      - http:
          path: hello
          method: GET

custom:
  serverless-offline:
    noPrependStageInUrl: true
    noTimeout: true
    port: 3000
    host: localhost
  s3:
    address: localhost
    host: localhost
    port: 9501
    directory: src/helpers/jwt/keys
  keysBucket: JWTKeys

resources:
  Resources:
    JWTKeys:
      Type: AWS::S3::Bucket
      Properties:
        BucketName: ${self:custom.keysBucket}

src/hello.ts:

import * as AWS from "aws-sdk";

const keysBucketName = process.env.keysBucket || '';

exports.handler = async function (event, context, callback) {
    const s3 = new AWS.S3({
        s3ForcePathStyle: true,
        accessKeyId: 'S3RVER',
        secretAccessKey: 'S3RVER',
        endpoint: new AWS.Endpoint('localhost:9501'),
    });

    const privateKey = await s3.getObject({
        Bucket: keysBucketName,
        Key: 'jwtRS256.key'
    }).promise();
    console.log(privateKey);

    return {
        statusCode: 200,
        body: JSON.stringify(event),
    };
};

So... With this setup, I receive this error:

UnknownEndpoint: Inaccessible host: `localhost'. This service may not be available in the `us-east-1' region.
at Request.ENOTFOUND_ERROR (/Users/nico/Desktop/serverless/lambda-app/node_modules/aws-sdk/lib/event_listeners.js:507:46)
at Request.callListeners (/Users/nico/Desktop/serverless/lambda-app/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
at Request.emit (/Users/nico/Desktop/serverless/lambda-app/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
at Request.emit (/Users/nico/Desktop/serverless/lambda-app/node_modules/aws-sdk/lib/request.js:688:14)
at ClientRequest.error (/Users/nico/Desktop/serverless/lambda-app/node_modules/aws-sdk/lib/event_listeners.js:339:22)
at ClientRequest.<anonymous> (/Users/nico/Desktop/serverless/lambda-app/node_modules/aws-sdk/lib/http/node.js:96:19)
at ClientRequest.emit (node:events:327:20)
at ClientRequest.EventEmitter.emit (node:domain:486:12)
at TLSSocket.socketErrorListener (node:_http_client:478:9)
at TLSSocket.emit (node:events:327:20)
at TLSSocket.EventEmitter.emit (node:domain:486:12)
at emitErrorNT (node:internal/streams/destroy:188:8)
at emitErrorCloseNT (node:internal/streams/destroy:153:3)
at processTicksAndRejections (node:internal/process/task_queues:80:21)

It seems like that it cannot connect to local s3.

Obv I use serverless offline start to start all the services.
Am i missing something?

@ar90n
Copy link
Owner

ar90n commented Dec 25, 2020

@Nicoxys
Thanks for your report!! As long as I read what you said, I guess it was caused by using HTTPS to access S3.
Please try the following code at initializing the S3 object.

        endpoint: new AWS.Endpoint('http://localhost:9501'),

@andreieuganox
Copy link

andreieuganox commented Mar 5, 2021

Default Port: 4569

endpoint: new AWS.Endpoint('localhost:9501'), -> endpoint: new AWS.Endpoint('localhost:4569'),

@reilg
Copy link

reilg commented Nov 2, 2021

I have the same issue and a similar simple setup except that I'm using new AWS.Endpoint('http://localhost:4569')

"UnknownEndpoint: Inaccessible host: `localhost'. This service may 
    not be available in the `us-east-1' region.

@bertrandmc
Copy link

bertrandmc commented Nov 18, 2022

I had to deal with this issue today, turns out I was passing the incorrect attribute when configuring the S3 service, forcePathStyle: true is for SDK 3, make sure you pass s3ForcePathStyle: true if you are using AWS SDK 2

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

5 participants