Skip to content

Commit

Permalink
Support writing Lambda logs (pulumi#555)
Browse files Browse the repository at this point in the history
Also add a couple things to the global .gitignore.
  • Loading branch information
lukehoban authored Feb 14, 2020
1 parent 974ec15 commit ec4f13c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Pulumi.*.yaml
*.iml
key.rsa*
obj/
vendor
Gopkg.lock

# Java app
.gradle/
Expand Down
24 changes: 23 additions & 1 deletion aws-go-lambda/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,23 @@ func main() {
return err
}

// Attach a policy to allow writing logs to CloudWatch
logPolicy, err := iam.NewRolePolicy(ctx, "lambda-log-policy", &iam.RolePolicyArgs{
Role: role.Name,
Policy: pulumi.String(`{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "arn:aws:logs:*:*:*"
}]
}`),
})

// Set arguments for constructing the function resource.
args := &lambda.FunctionArgs{
Handler: pulumi.String("handler"),
Expand All @@ -35,7 +52,12 @@ func main() {
}

// Create the lambda using the args.
function, err := lambda.NewFunction(ctx, "basicLambda", args)
function, err := lambda.NewFunction(
ctx,
"basicLambda",
args,
pulumi.DependsOn([]pulumi.Resource{logPolicy}),
)
if err != nil {
return err
}
Expand Down

0 comments on commit ec4f13c

Please sign in to comment.