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

DynamoDB Credential for sim #6463

Closed
thoroc opened this issue May 13, 2024 · 7 comments
Closed

DynamoDB Credential for sim #6463

thoroc opened this issue May 13, 2024 · 7 comments
Labels
🐛 bug Something isn't working community-request requested by community members 📚 libraries Wing Libraries

Comments

@thoroc
Copy link

thoroc commented May 13, 2024

I tried this:

I have tried to hardcode the credentials for the sim as per the test: https://github.com/winglang/winglibs/blob/main/dynamodb/tests/connection.test.w

This happened:

Still getting the following error message:

UnrecognizedClientException: The security token included in the request is invalid.

I expected this:

The credentials to be accepted as is

Is there a workaround?

Need to figure out how to give it actual credentials

Anything else?

Might need to figure out if Wing is capable to read creds from Leapp: https://www.leapp.cloud/

Wing Version

0.73.41

Node.js Version

20.11.0

Platform(s)

MacOS

Community Notes

  • Please vote by adding a 👍 reaction to the issue to help us prioritize.
  • If you are interested to work on this issue, please leave a comment.
@thoroc thoroc added the 🐛 bug Something isn't working label May 13, 2024
@ShaiBer ShaiBer added the community-request requested by community members label May 13, 2024
@thoroc
Copy link
Author

thoroc commented May 13, 2024

I have now tried the following:

  1. hard code the values in the main.w:
let sessionDbConnection: dynamodb.Connection = {
  tableName: sessionTable.tableName,
  clientConfig: {
    endpoint: "http://localhost:3000",
    region: AwsRegion,
    credentials: {
      accessKeyId: "local",
      secretAccessKey: "local"
    },
  }
};
  1. Pass them to the handler.w:
  new(options: types.SessionHandlerOptions) {
    this._credentials = options.clientOptions?.clientConfig?.credentials;
  }
  1. Create the client instance:
    let client = new dynamodb.Client({
      tableName: this._table.tableName, 
      credentials: {
        accessKeyId: this._credentials?.accessKeyId!, 
        secretAccessKey: this._credentials?.secretAccessKey!
      }
    });

I am now encountering the following error:

UnrecognizedClientException: The security token included in the request is invalid.

I am either doing it wrong and cannot read the docs (sic) or the local isn't being respected.

@skyrpex
Copy link
Contributor

skyrpex commented May 13, 2024

Ideally, you don't have to create a DynamoDB client by yourself. You should use the inflight API of the table directly, as in:

let table = new dynamodb.Table(...);

new cloud.Function(inflight () => {
  table.get(...);
});

The credentials, client instantiation and function permissions are managed for you this way.

@skyrpex
Copy link
Contributor

skyrpex commented May 13, 2024

The test https://github.com/winglang/winglibs/blob/main/dynamodb/tests/connection.test.w shows how to retrieve the table connection details (if you need to use them outside of wing), but I'm not sure that's your case here.

@Chriscbr Chriscbr added the 📚 libraries Wing Libraries label May 13, 2024
@MarkMcCulloh
Copy link
Contributor

Part of the confusion is that there are two structs called "Credentials" in the dynamodb winglib.

  1. https://github.com/winglang/winglibs/blob/d457129c67d3b0764a834d429642aae42fdeb28e/dynamodb/dynamodb-types.w#L184
  2. https://github.com/winglang/winglibs/blob/d457129c67d3b0764a834d429642aae42fdeb28e/dynamodb/dynamodb-client.w#L16

So wing considers these different types, and currently we don't structurally type check these so it fails (opened #6467 for this).
Also worth noting the second is not public, so #4655 is related as well.

@thoroc
Copy link
Author

thoroc commented May 14, 2024

@skyrpex I have followed your suggestion and used a dynamodb.Table directly.

@thoroc
Copy link
Author

thoroc commented May 14, 2024

@MarkMcCulloh Ok so already known issue. Feels free to close this. Thank you.

@skyrpex
Copy link
Contributor

skyrpex commented May 14, 2024

Part of the confusion is that there are two structs called "Credentials" in the dynamodb winglib.

Good catch, I can refactor that type... Here: winglang/winglibs#232

@skyrpex skyrpex closed this as completed May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working community-request requested by community members 📚 libraries Wing Libraries
Projects
Archived in project
Development

No branches or pull requests

5 participants