#✅ - Amplify Gen 2 storage

7 messages · Page 1 of 1 (latest)

frosty mesa
#

I've followed the docs and created the storage structure, the storage>resourse.ts, added it to backend.ts, I've also function permissions to it.

When I build I see the typescript type get added for functionName_BUCKET_NAME as it says in the docs but it dissapears.

How do I acess the bucked from the backend function? Also how can I fix that the type in type AmplifyBackendEnvVars is not appearing for the env var?

slim birch
#

can you share the code on how the permissions are added?

the auto population of the env vars is based on the following:

  • in the storage resouce, you use the allow function to assing permissions to a function. This instructs amplify what functions require access to the bucket
  • based on this, an env var is added to the env object that you can import
  • the build process for lambda will add some code before your supplied one that will:
  • query SSM for the bucket name
  • add this to the local env vars.

if you check the env params for lambda, in this scenario, you will actually find one of them that holds a JSON with the required mapping of SSM params to env params that enable this step.

#

I hope I didn't miss anything 😄

frosty mesa
#

Thanks for getting back to me, this is the code on the resource.ts in the storage dir.

I did check my s3 manually and I do see the bucket, so the resource is working, I must be doing something wrong with the permissions but I did follow the guide.

The actual function is defined using defineFunction but is imported into the storage/resource.ts file

export const getGearsWithServiceDetails = defineFunction({
  name: "get-gears-with-service-details",
  entry: "./handler.ts",
  }});

import { defineStorage } from '@aws-amplify/backend';
import { getGearsWithServiceDetails } from '../functions/get-gears-with-service-details/resource';

export const storage = defineStorage({
  name: 'strava-gear-sync',
  access: (allow) => ({
    'activities/*': [allow.resource(getGearsWithServiceDetails).to(['read', 'write', 'delete'])]
  })
});
lean flicker
#

the AmplifyBackendEnvVars files are re-generated on a sandbox/pipeline deploy. Are you seeing an error on either of these deploys?
The file might not generate if there was synth error while deploying.

frosty mesa
#

Aaaaaa figured it out, I was importing the wrong functions env, so silly

You helped me troubleshoot and thanks very much for that. I appriciate it.

wide idolBOT
#

✅ - Amplify Gen 2 storage