Is the document about globals section correct?
For now, this document says:
List value in the resource will replace with the map value from Global. Example:
SecurityGroupIds of VpcConfig will be set to ["sg-first"]
Globals:
Function:
VpcConfig:
SecurityGroupIds:
- sg-123
- sg-456
Resources:
MyFunction:
Type: AWS::Serverless::Function
Properties:
VpcConfig:
SecurityGroupIds:
- sg-first
But, this SAM template attaches 3 security groups( sg-958b48ec / sg-cb8d4eb2 / sg-808e4df9 ) to Lambda.
---
AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::Serverless-2016-10-31
Description: Sample 4
Globals:
Function:
Runtime: python3.6
Timeout: 60
Handler: index.handler
VpcConfig:
SubnetIds:
- subnet-98cd5bd1
- subnet-b3cc5afa
SecurityGroupIds:
- sg-958b48ec
- sg-cb8d4eb2
Resources:
Func1:
Type: AWS::Serverless::Function
Properties:
Policies:
- arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole
CodeUri: src/handlers/sample-func1
VpcConfig:
SecurityGroupIds:
- sg-808e4df9
I test that behavior with this environments.
- Tokyo/N.Virginia regions
- aws-sam-local: 0.2.2
- aws-cli: 1.14.2 Python/3.6.3 Darwin/17.2.0 botocore/1.8.6
I think list value in the resource will not replace with the map value from global, but will be added to the map value from global. Is this right?
@knakayama Thank you for catching this. It is an error in our documentation. Lists are additive and dictionaries are merged. Feel free to send a PR with that updated. I may be able to fix this tomorrow if I have a couple minutes, if you don't get to it before me.
Hmm, I wonder if this is a doc failure or a failure in the specification. E.g. We SHOULD overwrite instead. Would be interesting to see other's thoughts -- though as of today the two have diverged in what they do so the docs do need to be updated.
List being additive was done on purpose and is a doc failure. In some cases you want this additive behavior. For example:
Globals:
Function:
Runtime: python3.6
Policies:
- arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole
Resources:
Func1:
Type: AWS::Serverless::Function
Properties:
Policies:
- some-user-defined-policy-1
Func2:
Type: AWS::Serverless::Function
Properties:
Policies:
- some-user-defined-policy-2
I know we had some back and forth on this initially and we ended up going the additive route because of cases like these. I think globals become more powerful this way.
Documentation is updated.
Thanks!