https://pulumi.com logo
p

proud-tiger-5743

02/20/2019, 8:49 PM
When creating an S3 event handler for a Lambda
Copy code
const input = new aws.s3.Bucket('inputbucket')
input.onObjectCreated('testing',(event,context)=> {
  console.log(event)
},{keyPrefix: ".csv"},)
Is there a way to alter the IAM execution role?
h

helpful-ice-5738

02/20/2019, 8:56 PM
(not part of the pulumi team but i’ve been playing with lots of lambda/api gateway) it’s been easiest for me to create the lambda execution role and policy, associate them, and then associate the role with the lambda function
p

proud-tiger-5743

02/20/2019, 8:58 PM
That's a helpful workflow - where would you suggest I associate the role with the lambda in that example?
h

helpful-ice-5738

02/20/2019, 8:59 PM
are you using
aws.lambda.Function
?
p

proud-tiger-5743

02/20/2019, 8:59 PM
No
Can you still in-line the execution code with that constructor? I need to be able to pass in an ECS task execution as part of the function
h

helpful-ice-5738

02/20/2019, 9:00 PM
yeah, you can - what constructor are you using?
p

proud-tiger-5743

02/20/2019, 9:01 PM
I was just using
bucket.onObjectCreated
and passing in the function code
h

helpful-ice-5738

02/20/2019, 9:01 PM
ah I see - yeah, some of the other constructors wrap
aws.lambda.Function
but if you look to the source code you’ll see you can’t pass all the args you might need through those wrappers 😕
p

proud-tiger-5743

02/20/2019, 9:02 PM
Yeah
h

helpful-ice-5738

02/20/2019, 9:03 PM
hopefully you can find a way to modify 😛 I assume if you can grab the arn (I’d use outputs to dump the data structure of whatever gets created and then pull the arn from that, if it exists) then you can attach a policy to that role
p

proud-tiger-5743

02/20/2019, 9:04 PM
If this is the constructor to use
Copy code
const testLambda = new aws.lambda.Function("test_lambda", {
    environment: {
        variables: {
            foo: "bar",
        },
    },
    code: new pulumi.asset.FileArchive("lambda_function_payload.zip"),
    name: "lambda_function_name",
    handler: "exports.test",
    role: iamForLambda.arn,
    runtime: "nodejs8.10",
});
any idea how to write the function in-line?
h

helpful-ice-5738

02/20/2019, 9:06 PM
I imagine you can backtick it — so :
Copy code
const testLambda = new aws.lambda.Function("test_lambda", {
    environment: {
        variables: {
            foo: "bar",
        },
    },
    code: ` your code goes here \ 
some more code`,
    name: "lambda_function_name",
    handler: "exports.test",
    role: iamForLambda.arn,
    runtime: "nodejs8.10",
});
p

proud-tiger-5743

02/20/2019, 9:07 PM
hmmm - I'll give that a try!!
Thanks