Skip to content

Commit

Permalink
fix: Add MergeDefinitions property to Global Section (aws#2976)
Browse files Browse the repository at this point in the history
  • Loading branch information
GavinZZ committed Mar 2, 2023
1 parent 9817573 commit cc14009
Show file tree
Hide file tree
Showing 6 changed files with 613 additions and 2 deletions.
1 change: 1 addition & 0 deletions samtranslator/plugins/globals/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class Globals:
"DefinitionUri",
"CacheClusterEnabled",
"CacheClusterSize",
"MergeDefinitions",
"Variables",
"EndpointConfiguration",
"MethodSettings",
Expand Down
60 changes: 60 additions & 0 deletions tests/translator/input/api_merge_definitions_global.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
Transform: AWS::Serverless-2016-10-31

Globals:
Api:
MergeDefinitions: true

Resources:
MyApi:
Type: AWS::Serverless::Api
Properties:
StageName: Prod
DefinitionBody:
swagger: '2.0'
info:
title: Example
version: '1'
paths:
/test:
get:
security:
MyAuthorizer2: []
Auth:
Authorizers:
MyAuthorizer:
UserPoolArn: !GetAtt MyCognitoUserPool.Arn

MyAuthorizer2:
UserPoolArn: !GetAtt MyCognitoUserPool2.Arn

MyFunction:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: nodejs14.x
InlineCode: |
exports.handler = async (event, context, callback) => {
return {
statusCode: 200,
body: 'Success'
}
}
Events:
MyEventV1:
Type: Api
Properties:
RestApiId: !Ref MyApi
Path: /test
Method: get
Auth:
Authorizer: MyAuthorizer

MyCognitoUserPool:
Type: AWS::Cognito::UserPool
Properties:
UserPoolName: MyCognitoUserPoolRandomName

MyCognitoUserPool2:
Type: AWS::Cognito::UserPool
Properties:
UserPoolName: MyCognitoUserPoolRandomName2
178 changes: 178 additions & 0 deletions tests/translator/output/api_merge_definitions_global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
{
"Resources": {
"MyApi": {
"Properties": {
"Body": {
"info": {
"title": "Example",
"version": "1"
},
"paths": {
"/test": {
"get": {
"responses": {},
"security": [
{
"MyAuthorizer": []
}
],
"x-amazon-apigateway-integration": {
"httpMethod": "POST",
"type": "aws_proxy",
"uri": {
"Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations"
}
}
}
}
},
"securityDefinitions": {
"MyAuthorizer": {
"in": "header",
"name": "Authorization",
"type": "apiKey",
"x-amazon-apigateway-authorizer": {
"providerARNs": [
{
"Fn::GetAtt": [
"MyCognitoUserPool",
"Arn"
]
}
],
"type": "cognito_user_pools"
},
"x-amazon-apigateway-authtype": "cognito_user_pools"
},
"MyAuthorizer2": {
"in": "header",
"name": "Authorization",
"type": "apiKey",
"x-amazon-apigateway-authorizer": {
"providerARNs": [
{
"Fn::GetAtt": [
"MyCognitoUserPool2",
"Arn"
]
}
],
"type": "cognito_user_pools"
},
"x-amazon-apigateway-authtype": "cognito_user_pools"
}
},
"swagger": "2.0"
}
},
"Type": "AWS::ApiGateway::RestApi"
},
"MyApiDeploymentf4bf62db4c": {
"Properties": {
"Description": "RestApi deployment id: f4bf62db4c8bd0cbd8276f47c4280a81f4adec16",
"RestApiId": {
"Ref": "MyApi"
},
"StageName": "Stage"
},
"Type": "AWS::ApiGateway::Deployment"
},
"MyApiProdStage": {
"Properties": {
"DeploymentId": {
"Ref": "MyApiDeploymentf4bf62db4c"
},
"RestApiId": {
"Ref": "MyApi"
},
"StageName": "Prod"
},
"Type": "AWS::ApiGateway::Stage"
},
"MyCognitoUserPool": {
"Properties": {
"UserPoolName": "MyCognitoUserPoolRandomName"
},
"Type": "AWS::Cognito::UserPool"
},
"MyCognitoUserPool2": {
"Properties": {
"UserPoolName": "MyCognitoUserPoolRandomName2"
},
"Type": "AWS::Cognito::UserPool"
},
"MyFunction": {
"Properties": {
"Code": {
"ZipFile": "exports.handler = async (event, context, callback) => {\n return {\n statusCode: 200,\n body: 'Success'\n }\n}\n"
},
"Handler": "index.handler",
"Role": {
"Fn::GetAtt": [
"MyFunctionRole",
"Arn"
]
},
"Runtime": "nodejs14.x",
"Tags": [
{
"Key": "lambda:createdBy",
"Value": "SAM"
}
]
},
"Type": "AWS::Lambda::Function"
},
"MyFunctionMyEventV1PermissionProd": {
"Properties": {
"Action": "lambda:InvokeFunction",
"FunctionName": {
"Ref": "MyFunction"
},
"Principal": "apigateway.amazonaws.com",
"SourceArn": {
"Fn::Sub": [
"arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/test",
{
"__ApiId__": {
"Ref": "MyApi"
},
"__Stage__": "*"
}
]
}
},
"Type": "AWS::Lambda::Permission"
},
"MyFunctionRole": {
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": [
"sts:AssumeRole"
],
"Effect": "Allow",
"Principal": {
"Service": [
"lambda.amazonaws.com"
]
}
}
],
"Version": "2012-10-17"
},
"ManagedPolicyArns": [
"arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
],
"Tags": [
{
"Key": "lambda:createdBy",
"Value": "SAM"
}
]
},
"Type": "AWS::IAM::Role"
}
}
}
Loading

0 comments on commit cc14009

Please sign in to comment.