Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add MergeDefinitions property to Global Section #2976

Merged
merged 3 commits into from
Feb 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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