From f47abe0c697d25503bb961c61b854b15b779ecac Mon Sep 17 00:00:00 2001 From: eugeniosu Date: Mon, 28 Oct 2019 22:48:19 -0300 Subject: [PATCH] Adding VPC Access Policy when VpcConfig is present --- samtranslator/model/sam_resources.py | 4 ++++ tests/translator/output/aws-cn/globals_for_function.json | 6 ++++-- .../translator/output/aws-us-gov/globals_for_function.json | 6 ++++-- tests/translator/output/globals_for_function.json | 6 ++++-- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/samtranslator/model/sam_resources.py b/samtranslator/model/sam_resources.py index 4335987c7..ae6de90f8 100644 --- a/samtranslator/model/sam_resources.py +++ b/samtranslator/model/sam_resources.py @@ -198,6 +198,10 @@ def _construct_role(self, managed_policy_map): managed_policy_arns = [ArnGenerator.generate_aws_managed_policy_arn('service-role/AWSLambdaBasicExecutionRole')] if self.Tracing: managed_policy_arns.append(ArnGenerator.generate_aws_managed_policy_arn('AWSXrayWriteOnlyAccess')) + if self.VpcConfig: + managed_policy_arns.append( + ArnGenerator.generate_aws_managed_policy_arn('service-role/AWSLambdaVPCAccessExecutionRole') + ) function_policies = FunctionPolicies({"Policies": self.Policies}, # No support for policy templates in the "core" diff --git a/tests/translator/output/aws-cn/globals_for_function.json b/tests/translator/output/aws-cn/globals_for_function.json index 68cb93e88..d23c1c131 100644 --- a/tests/translator/output/aws-cn/globals_for_function.json +++ b/tests/translator/output/aws-cn/globals_for_function.json @@ -5,7 +5,8 @@ "Properties": { "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws-cn:iam::aws:policy/AWSXrayWriteOnlyAccess" + "arn:aws-cn:iam::aws:policy/AWSXrayWriteOnlyAccess", + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole" ], "PermissionsBoundary": "arn:aws:1234:iam:boundary/OverridePermissionsBoundary", "AssumeRolePolicyDocument": { @@ -92,7 +93,8 @@ "Properties": { "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws-cn:iam::aws:policy/AWSXrayWriteOnlyAccess" + "arn:aws-cn:iam::aws:policy/AWSXrayWriteOnlyAccess", + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole" ], "PermissionsBoundary": "arn:aws:1234:iam:boundary/CustomerCreatedPermissionsBoundary", "AssumeRolePolicyDocument": { diff --git a/tests/translator/output/aws-us-gov/globals_for_function.json b/tests/translator/output/aws-us-gov/globals_for_function.json index e087c7180..bedc4cf16 100644 --- a/tests/translator/output/aws-us-gov/globals_for_function.json +++ b/tests/translator/output/aws-us-gov/globals_for_function.json @@ -5,7 +5,8 @@ "Properties": { "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws-us-gov:iam::aws:policy/AWSXrayWriteOnlyAccess" + "arn:aws-us-gov:iam::aws:policy/AWSXrayWriteOnlyAccess", + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole" ], "PermissionsBoundary": "arn:aws:1234:iam:boundary/OverridePermissionsBoundary", "AssumeRolePolicyDocument": { @@ -92,7 +93,8 @@ "Properties": { "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws-us-gov:iam::aws:policy/AWSXrayWriteOnlyAccess" + "arn:aws-us-gov:iam::aws:policy/AWSXrayWriteOnlyAccess", + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole" ], "PermissionsBoundary": "arn:aws:1234:iam:boundary/CustomerCreatedPermissionsBoundary", "AssumeRolePolicyDocument": { diff --git a/tests/translator/output/globals_for_function.json b/tests/translator/output/globals_for_function.json index 0cf77bc37..0a2fa8ec7 100644 --- a/tests/translator/output/globals_for_function.json +++ b/tests/translator/output/globals_for_function.json @@ -5,7 +5,8 @@ "Properties": { "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws:iam::aws:policy/AWSXrayWriteOnlyAccess" + "arn:aws:iam::aws:policy/AWSXrayWriteOnlyAccess", + "arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole" ], "PermissionsBoundary": "arn:aws:1234:iam:boundary/OverridePermissionsBoundary", "AssumeRolePolicyDocument": { @@ -92,7 +93,8 @@ "Properties": { "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws:iam::aws:policy/AWSXrayWriteOnlyAccess" + "arn:aws:iam::aws:policy/AWSXrayWriteOnlyAccess", + "arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole" ], "PermissionsBoundary": "arn:aws:1234:iam:boundary/CustomerCreatedPermissionsBoundary", "AssumeRolePolicyDocument": {