localstack / awscli-local

💲 "awslocal" - Thin wrapper around the "aws" command line interface for use with LocalStack
Apache License 2.0
1.09k stars 86 forks source link

[bug]: Can't add url config for lambda in local stack using aws-sdk #70

Closed spelexander closed 1 year ago

spelexander commented 1 year ago

Hi! first off thanks for a useful library for emulating AWS resources locally.

The issue I'm encountering is using the nodejs aws-sdk to create resources in localstack.

If I create a lambda, and then try to create/list/get a URL config for the lambda I get the following error which provides nothing to go off of for investigation:

Error [UnknownError]
    at Object.extractError (/Users/aspence/src/canvas/node_modules/aws-sdk/lib/protocol/json.js:52:27)
    at Request.extractError (/Users/aspence/src/canvas/node_modules/aws-sdk/lib/protocol/rest_json.js:61:8)
    at Request.callListeners (/Users/aspence/src/canvas/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
    at Request.emit (/Users/aspence/src/canvas/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
    at Request.emit (/Users/aspence/src/canvas/node_modules/aws-sdk/lib/request.js:686:14)
    at Request.transition (/Users/aspence/src/canvas/node_modules/aws-sdk/lib/request.js:22:10)
    at AcceptorStateMachine.runTo (/Users/aspence/src/canvas/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at /Users/aspence/src/canvas/node_modules/aws-sdk/lib/state_machine.js:26:10
    at Request.<anonymous> (/Users/aspence/src/canvas/node_modules/aws-sdk/lib/request.js:38:9)
    at Request.<anonymous> (/Users/aspence/src/canvas/node_modules/aws-sdk/lib/request.js:688:12)
    at Request.callListeners (/Users/aspence/src/canvas/node_modules/aws-sdk/lib/sequential_executor.js:116:18)
    at Request.emit (/Users/aspence/src/canvas/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
    at Request.emit (/Users/aspence/src/canvas/node_modules/aws-sdk/lib/request.js:686:14)
    at Request.transition (/Users/aspence/src/canvas/node_modules/aws-sdk/lib/request.js:22:10)
    at AcceptorStateMachine.runTo (/Users/aspence/src/canvas/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at /Users/aspence/src/canvas/node_modules/aws-sdk/lib/state_machine.js:26:10 {
  code: 'UnknownError',
  statusCode: 404,
  time: 2022-12-22T01:19:24.624Z,
  requestId: undefined,
  retryable: false,
  retryDelay: 48.11161846934877
}
create-resources started 907

See an reproducible example below, assuming 'test-lambda' has already been created:

import { Lambda } from 'aws-sdk';

import { buildWorker, packageWorker } from './workers';

const lambda = new Lambda({
  region: 'us-east-1',
  endpoint: 'http://localhost:4566',
});

const name = 'test-lambda';

it('Test create resources', async () => {
  lambda.addPermission({
    FunctionName: name,
    Action: 'lambda:InvokeFunctionUrl',
    Principal: '*',
    FunctionUrlAuthType: 'NONE',
    StatementId: '/',
  });

  try {
    // THIS FAILS
    // So does the list, or get commands
    const result = await lambda
      .createFunctionUrlConfig({
        FunctionName: name,
        AuthType: 'NONE',
      })
      .promise();
    console.log('result: ', result);
  } catch (e) {
    console.error(e);
  }
});