Here is how I do this:
- Create a managed policy with access to your AppConfig
- Attach that managed policy to the role your lambda is configured to use
Here is the code using CDK (CDK is the latest and greatest tool to create AWS resources, I highly recommend using it!).
If you don't want to use CDK you can manually setup the same managed policies by hand.
Detailed example below:
Create a managed policy with access to your AppConfig
const resourceArn = `arn:aws:appconfig:${props.region}:${props.accountId}:application/${this.appConfigApplication.ref}*`
this.appConfigReaderManagedPolicy = new ManagedPolicy(this, `AppConfigReader-${id}`, {
managedPolicyName: `AppConfigReader-${id}`,
description: `Readonly access to ${id}`,
statements: [
new PolicyStatement({
resources: [resourceArn],
actions: [
'appconfig:GetConfiguration',
'appconfig:GetApplication',
]
})
]
})
Attach that managed policy to the role your lambda is configured to use
//assuming your lambda is already configured somewhere
this.lambdaFunction.role.addManagedPolicy(this.appConfigReaderManagedPolicy)