Skip to content

How to add conditions to the IAM role statements for a specific function: #129

@s1mrankaur

Description

@s1mrankaur

Here's a basic example of what I'd like to be able to do:

`service: my-service

provider:
name: aws
runtime: nodejs18.x

plugins:

  • serverless-iam-roles-per-function

functions:
myFunction:
handler: handler.myFunction
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:Query
- dynamodb:Scan
Resource: arn:aws:dynamodb:us-east-1:123456789012:table/my-table
Condition:
StringEquals:
"dynamodb:LeadingKeys": "userId"

secondFunction:
handler: handler.secondFunction
iamRoleStatements:
- Effect: Allow
Action:
- dynamoDB:UpdateItem
Resource: arn:aws:dynamodb:us-east-1:123456789012:table/my-table
Condition:
ForAllValues:StringNotLike:
"dynamodb:Attributes":[
"FreeGamesAvailable",
"BossLevelUnlocked"
]

anotherFunction:
handler: handler.anotherFunction
iamRoleStatements:
- Effect: Allow
Action:
- s3:GetObject
Resource: arn:aws:s3:::my-bucket/*
Condition:
IpAddress:
"aws:SourceIp": "203.0.113.0/24"`

If this isn't supported currently by the package, what are my options?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions