Skip to content

Commit

Permalink
Add support for multiple AWS regions to Functionbeat (elastic#21065)
Browse files Browse the repository at this point in the history
(cherry picked from commit ee95f3d)
  • Loading branch information
rnaik-godaddy authored and kvch committed Jan 11, 2021
1 parent bc888ce commit dc7f130
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,7 @@ port. {pull}19209[19209]
*Functionbeat*

- Provide more ways to set AWS credentials. {issue}12464[12464] {pull}23344[23344]
- Add support for multiple regions {pull}21065[21065]

*Winlogbeat*

Expand Down
11 changes: 9 additions & 2 deletions x-pack/functionbeat/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ import (
)

var (
functionPattern = "^[A-Za-z][A-Za-z0-9\\-]{0,139}$"
// We're appending the function name to the role name.
// Limiting this to 30 because, we're prefixing the role name
// with "functionbeat-lambda-"(20 chars) and suffixing with
// the region, the max of which is "ap-southeast-2" (14 chars)
// Length constraints for roleName in AWS is 64 characters max per
// https://docs.aws.amazon.com/IAM/latest/APIReference/API_CreateRole.html

functionPattern = "^[A-Za-z][A-Za-z0-9\\-]{0,30}$"
functionRE = regexp.MustCompile(functionPattern)
configOverrides = common.MustNewConfigFrom(map[string]interface{}{
"path.data": "/tmp",
Expand Down Expand Up @@ -103,7 +110,7 @@ type functionName string
func (f *functionName) Unpack(s string) error {
if !functionRE.MatchString(s) {
return fmt.Errorf(
"invalid name: '%s', name must match [a-zA-Z0-9-] and be at most 140 characters",
"invalid name: '%s', name must match [a-zA-Z0-9-] and be at most 30 characters",
s,
)
}
Expand Down
15 changes: 15 additions & 0 deletions x-pack/functionbeat/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,24 @@ func TestFunctionName(t *testing.T) {
assert.Equal(t, functionName("hello-world"), f)
})

t.Run("valid function name: length of 30 chars", func(t *testing.T) {
f := functionName("")
err := f.Unpack("something-which-is--30--chars")
if !assert.NoError(t, err) {
return
}
assert.Equal(t, functionName("something-which-is--30--chars"), f)
})

t.Run("invalid function name", func(t *testing.T) {
f := functionName("")
err := f.Unpack("hello world")
assert.Error(t, err)
})

t.Run("invalid function name: length", func(t *testing.T) {
f := functionName("")
err := f.Unpack("something-which-is-greater-than-thirty-characters")
assert.Error(t, err)
})
}
2 changes: 1 addition & 1 deletion x-pack/functionbeat/manager/aws/template_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ func (d *defaultTemplateBuilder) roleTemplate(function installer, name string) *
},
},
Path: "/",
RoleName: "functionbeat-lambda-" + name,
RoleName: "functionbeat-lambda-" + name + "-" + cloudformation.Ref("AWS::Region"),
// Allow the lambda to write log to cloudwatch logs.
// doc: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-iam-policy.html
Policies: policies,
Expand Down

0 comments on commit dc7f130

Please sign in to comment.