classmethod / gradle-aws-plugin

Gradle plugin to manage Amazon Web Services
276 stars 132 forks source link

Add ability to create lambda resource policies #189

Closed miguelaferreira closed 3 years ago

miguelaferreira commented 4 years ago

Thanks for this very useful plugin. While using it I missed the ability to set resource policies on lambda functions in order to allow other services (in my case Amazon Lex) to invoke the lambdas I deploy via the plugin.

This is my first attempt at contributing to a gradle plugin and, I've made this PR with my own use case in mind and no other. Therefore, I will be very happy to receive feedback to improve this PR since I expect that there will be lots of things that can be done better.

I'm currently using the feature introduced in this PR as follows

import jp.classmethod.aws.gradle.lambda.ResourcePermission;

task deploy(type: jp.classmethod.aws.gradle.lambda.AWSLambdaMigrateFunctionTask, dependsOn: shadowJar) {
    functionName = "myFunction"
    handler = "com.example.Function::apply"
    role = "arn:aws:iam::${aws.accountId}:role/service-role/some-role"
    runtime = com.amazonaws.services.lambda.model.Runtime.Java8
    zipFile = shadowJar.archivePath
    memorySize = 256
    timeout = 60

    resourcePermissions = [ResourcePermission.of("testStatement", "lambda:invokeFunction", "lex.amazonaws.com", "arn:aws:lex:eu-west-1:123458678910:intent:*")]
}

I wanted to configure the resourcePermissions property using a groovy map (expecting it to be serialised to the right class) but that did not work.

miguelaferreira commented 3 years ago

Closing this as projects seems inactive.