paws-r / paws

Paws, a package for Amazon Web Services in R
https://www.paws-r-sdk.com
Other
313 stars 37 forks source link

A few issues with sts_assume_role_with_web_identity #807

Closed sluga closed 1 month ago

sluga commented 1 month ago

Hi,

I'm using sts_assume_role_with_web_identity to generate temporary credentials for S3. I managed to get it to work but encountered a few issues along the way.

  1. The function is documented but not exported, the following snippet returns an error ('sts_assume_role_with_web_identity' is not an exported object from 'namespace:paws.security.identity').
# does not work
creds <- paws.security.identity::sts_assume_role_with_web_identity(
    RoleArn          = 'my-role',
    RoleSessionName  = 'my-session',
    WebIdentityToken = 'my-token'
)
  1. I can access the non-exported version but I cannot call it directly, the error I get is Error in eval(call[[2]], envir = calling_env) : object 'paws.security.identity' not found.
# does not work
creds <- paws.security.identity:::sts_assume_role_with_web_identity(
    RoleArn          = 'my-role',
    RoleSessionName  = 'my-session',
    WebIdentityToken = 'my-token'
)

To get it to work, I first have to assign the function to another name:

# works
fun <- paws.security.identity:::sts_assume_role_with_web_identity
creds <- fun(
    RoleArn          = 'my-role',
    RoleSessionName  = 'my-session',
    WebIdentityToken = 'my-token'
)

Versions:

DyfanJones commented 1 month ago

Paws doesn't work like the example you have provided. First you need to create the client. In this case sts. Then you need to call the operation

library(paws)

client <- sts()

client$assume_role(
    RoleArn = 'my-role',
    RoleSessionName  = 'my-session',
    WebIdentityToken = 'my-token'
)

paws provides request syntax example in how to use the operations https://www.paws-r-sdk.com/docs/sts_assume_role/#request-syntax

The reason for the 2 stage approach has a number of reason

sluga commented 1 month ago

Thanks for the correction, guess I should've spent more time checking the docs :) (BTW assume_role -> assume_role_with_web_identity in your snippet)