How to connect to Amazon Rekognition using paws package in R

373 Views Asked by At

I would like to connect to the AWS Rekognition package using R. The package "paws" in CRAN seems to cover this. However it fails to work due to an error "Error in get_region(): no region provided" despite the fact that it is specified in Sys.setenv. Note the "image.jpg" is a local image that is converted to base64enc using knitr to send to the Rekognition API using the detect_labels command in rekognition(), part of paws package.

library(paws)
library(knitr)
Sys.setenv("AWS_ACCESS_KEY_ID" = "xxxxxx", "AWS_SECRET_ACCESS_KEY" = "xxxx", "AWS_DEFAULT_REGION"= "eu-west-2")

svc <- rekognition()
img_X <- image_uri("image.jpg") 
svc$detect_labels(Image=img_X) 

Error in get_region() : No region provided

1

There are 1 best solutions below

2
On BEST ANSWER

Try Sys.setenv(AWS_REGION = "eu-west-2"). This worked for me.

Full code:

Sys.setenv(AWS_REGION = "eu-west-2")

library(paws.machine.learning)

svc <- paws.machine.learning::rekognition()

# image in S3 bucket
svc$detect_text(
  Image = list(
    S3Object = list(
      Bucket = "bucket",
      Name = "path_to_image"
    )
  )
)

# Local image
download.file("https://www.freecodecamp.org/news/content/images/2019/08/0_4ty0Adbdg4dsVBo3.png",'test.png', mode = 'wb')

svc$detect_text(
  Image = list(
    Bytes = "test.png"
  )
)