# FunctionBeat: incorrect IAM Service Principal for Lambda in AWS China regions

**URL:** <https://discuss.elastic.co/t/functionbeat-incorrect-iam-service-principal-for-lambda-in-aws-china-regions/225775>\
**Category:** Beats\
**Created:** [March 31, 2020, 2:59am UTC](https://discuss.elastic.co/t/functionbeat-incorrect-iam-service-principal-for-lambda-in-aws-china-regions/225775 "2020-03-31T02:59:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![henrysher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/henrysher/32/65344_2.png) [@henrysher](https://discuss.elastic.co/u/henrysher)\
**Post date:** [March 31, 2020, 2:59am UTC](https://discuss.elastic.co/t/functionbeat-incorrect-iam-service-principal-for-lambda-in-aws-china-regions/225775/1 "2020-03-31T02:59:39Z")

</div>

Hello,

I have tested FunctionBeat in AWS China region with those errors:

```auto
2020-03-31T12:13:10.748+0800	INFO	[aws]	aws/op_cloudformation.go:97	Stack event received, ResourceType: AWS::IAM::Role, LogicalResourceId: fnbcloudwatchIAMRoleLambdaExecution, ResourceStatus: CREATE_IN_PROGRESS
2020-03-31T12:13:10.748+0800	INFO	[aws]	aws/op_cloudformation.go:97	Stack event received, ResourceType: AWS::Logs::LogGroup, LogicalResourceId: fnbcloudwatchLogGroup, ResourceStatus: CREATE_IN_PROGRESS
2020-03-31T12:13:10.748+0800	INFO	[aws]	aws/op_cloudformation.go:97	Stack event received, ResourceType: AWS::IAM::Role, LogicalResourceId: fnbcloudwatchIAMRoleLambdaExecution, ResourceStatus: CREATE_FAILED, ResourceStatusReason: Invalid principal in policy: "SERVICE":"lambda.amazonaws.com.cn" (Service: AmazonIdentityManagement; Status Code: 400; Error Code: MalformedPolicyDocument; Request ID: 33c06f52-b16e-4a33-9b95-36ecb81361ab)
2020-03-31T12:13:10.748+0800	INFO	[aws]	aws/op_cloudformation.go:97	Stack event received, ResourceType: AWS::Logs::LogGroup, LogicalResourceId: fnbcloudwatchLogGroup, ResourceStatus: CREATE_IN_PROGRESS, ResourceStatusReason: Resource creation Initiated
2020-03-31T12:13:10.748+0800	INFO	[aws]	aws/op_cloudformation.go:97	Stack event received, ResourceType: AWS::Logs::LogGroup, LogicalResourceId: fnbcloudwatchLogGroup, ResourceStatus: CREATE_FAILED, ResourceStatusReason: Resource creation cancelled

```

And I also verified the exported cfn template and found the root cause: incorrect IAM service principal for lambda in AWS China regions.

According to the code from line 257 to 261  
in [https://github.com/elastic/beats/blob/master/x-pack/functionbeat/manager/aws/template\_builder.go](https://github.com/elastic/beats/blob/master/x-pack/functionbeat/manager/aws/template_builder.go), it has used the cfn pre-defined parameter "AWS::URLSuffix", for AWS global regions: [amazonaws.com](http://amazonaws.com), for AWS China regions: [amazonaws.com.cn](http://amazonaws.com.cn).

However, "[lambda.amazonaws.com.cn](http://lambda.amazonaws.com.cn)" is not the correct IAM service principal for Lambda in AWS China regions but it is "[lambda.amazonaws.com](http://lambda.amazonaws.com)". And you can further refer to my latest validation in [https://github.com/henrysher/aws-china-iam-service-principal-list](https://github.com/henrysher/aws-china-iam-service-principal-list).

Thanks!  
Henry

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 28, 2020, 5:00am UTC](https://discuss.elastic.co/t/functionbeat-incorrect-iam-service-principal-for-lambda-in-aws-china-regions/225775/2 "2020-04-28T05:00:02Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
