You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note, that in order to give my lambda function permissions to access the S3 bucket, I need to import my function into my storage definition. This means that I cannot import storage into my function definition to pass the bucket name as an environment variable, because that would be a cyclic dependency.
So instead, I try adding the environement variable to the lamdba function in the backend definition, like this:
I can see after doing this, in the AWS lambda console, the environment variable BUCKET_NAME is set.
However, when I try to use it in my handler, by passing it to the downloadData function, like this:
Note that I cannot use env.BUCKET_NAME to access the parameter, because it does not exist on env (presumably because it was not provided under environment property during the defineFunction call).
While this works, I don't think it is how the Amplify Team intended it to work.
If I do not provide the buckeName to the downloadData function, then I get this error: NoBucket: Missing bucket name while accessing object
According to the (Amplify docs)[https://docs.amplify.aws/javascript/build-a-backend/storage/download-files/] some default bucket should be used if I do tno provide one. But it is unclear how the config for this default bucket is to be passed into the lambda handler.
How am I supposed to be importing my bucket configuration into the lamdba handler?
The text was updated successfully, but these errors were encountered:
Amplify CLI Version
12.14.2
Amplify Version
^6.12.3
Description of use case
I have a lambda function. That lambda function should be able to read data from an S3 bucket. How do I pass the bucket name to the lambda function?
I have a lambda function defined like this
I have my storage defined like this
Note, that in order to give my lambda function permissions to access the S3 bucket, I need to import my function into my storage definition. This means that I cannot import storage into my function definition to pass the bucket name as an environment variable, because that would be a cyclic dependency.
So instead, I try adding the environement variable to the lamdba function in the backend definition, like this:
I can see after doing this, in the AWS lambda console, the environment variable BUCKET_NAME is set.
However, when I try to use it in my handler, by passing it to the
downloadData
function, like this:Note that I cannot use
env.BUCKET_NAME
to access the parameter, because it does not exist onenv
(presumably because it was not provided underenvironment
property during thedefineFunction
call).While this works, I don't think it is how the Amplify Team intended it to work.
If I do not provide the
buckeName
to thedownloadData
function, then I get this error:NoBucket: Missing bucket name while accessing object
According to the (Amplify docs)[https://docs.amplify.aws/javascript/build-a-backend/storage/download-files/] some default bucket should be used if I do tno provide one. But it is unclear how the config for this default bucket is to be passed into the lambda handler.
How am I supposed to be importing my bucket configuration into the lamdba handler?
The text was updated successfully, but these errors were encountered: