2

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

Ramón J Romero y Vigil
  • 17,373
  • 7
  • 77
  • 125
Darren
  • 83
  • 7

1 Answers1

1

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"
  )
)

Danny Morris
  • 82
  • 1
  • 6
  • Brilliant, solves the region issue! Thank you. Unfortunately it does not work with a local image converted to base64enc (ie not stored in a bucket). I get "Value null at 'image' failed to satisfy constraint: Member must not be null". Have you tried sending images directly, ie avoiding storing in buckets? – Darren Sep 26 '19 at 16:01
  • I edited the answer to include an example that passes a local image – Danny Morris Sep 27 '19 at 02:06