paws-r / paws

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

Can't update lambda function with Ephemeral Stroage #767

Closed spark0510 closed 3 months ago

spark0510 commented 3 months ago

Hi!

Thank you for making such a wonderful R package. While I'm using this package for registering & updating lambda functions (lambda$update_function_configuration and lambda$create_function), I found that everything is fine, but EphemeralStorage, one of arguments, is not updated.

Could you check this problem? Thank you!

DyfanJones commented 3 months ago

Hi @spark0510 sorry about the delay. I have been a bit ill over the last couple of days. When you say not updated? Is this the documentation or the functionality doesn't work?

Any code examples are a massive help. As I can try and replicate the issue in my Aws environment.

DyfanJones commented 3 months ago

It seems to work as expected through code:

library(paws)
client <- lambda(config(credentials(profile = "paws")))

client$update_function_configuration(
  FunctionName = "paws-demo",
  EphemeralStorage = list(Size = 512)
)$EphemeralStorage
#> $Size
#> [1] 512

# Back off for 2 seconds
Sys.sleep(2L)

client$update_function_configuration(
  FunctionName = "paws-demo",
  EphemeralStorage = list(Size = 526)
)$EphemeralStorage
#> $Size
#> [1] 526

Created on 2024-04-03 with reprex v2.1.0

DyfanJones commented 3 months ago

I believe create_function is working correctly as well. Here is a code snippet if you wish to test.

NOTE: Make sure you're using your own execution role :)

library(paws)

client <- lambda(config(credentials(profile = "paws")))

# Basic lambda function code
"import json

def lambda_handler(event, context):
  return {
    'statusCode': 200,
    'body': json.dumps('YAY ANOTHER LAMBDA FUNCTION')
  }
" |> writeLines("lambda_function.py")

# zipping up file for lambda
zip("temp.zip", "lambda_function.py")

# create lambda with increased EphemeralStorage size
resp <- client$create_function(
  FunctionName = "removable",
  Runtime = "python3.12",
  Role = "arn:aws:iam::123456789:role/service-role/your-execution-role",
  Handler = "lambda_function.lambda_handler",
  Code = list(
    'ZipFile'= readBin("temp.zip", "raw", file.size("temp.zip"))
  ),
  EphemeralStorage = list(Size = 1000)
)

resp$EphemeralStorage
#> $Size
#> [1] 1000

# Wait for 2 seconds when function is being created
Sys.sleep(2L)

# Check if lambda is working correctly
client$invoke(
  FunctionName = "removable"
)$Payload |> yyjsonr::read_json_raw()
#> $statusCode
#> [1] 200
#> 
#> $body
#> [1] "\"YAY ANOTHER LAMBDA FUNCTION\""

# Check lambda configuration
client$get_function_configuration(FunctionName = "removable")$EphemeralStorage
#> $Size
#> [1] 1000

# tidy up and remove lambda and any extra files
client$delete_function(FunctionName = "removable")
#> list()
fs::file_delete(c("temp.zip", "lambda_function.py"))

Created on 2024-04-03 with reprex v2.1.0

DyfanJones commented 3 months ago

I will label this as a question for now. If I have miss understood anything please let me know and I am happy to investigate it further.

spark0510 commented 3 months ago

I appreciate for the response! I hope you get better!

I've noticed that I misused the argument, specifically EphemeralStorage = 1000. It's functioning properly with the list type.

Once again, thank you!