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

Support AWS Lambda Function URLs #58

Merged
merged 4 commits into from
Sep 5, 2022
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
4 changes: 3 additions & 1 deletion src/AWSLambdaFunctions/Properties.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,16 @@
Timer-> A timer trigger lets you run a function on a schedule.
Queue-> A Queue Storage trigger function.
Event Bridge-> A Event Bridge (Event bus) trigger function.
Http-> A function that gets triggered by an Http Endpoint. Only API Objects or REST Procedures can be deployed.
</Description>
<Type>Combo</Type>
<Default>queue</Default>
<Metadata/>
<Values>
<Value id="timer" desc="Timer"/>
<Value id="queue" desc="Queue"/>
<Value id="eventbridge" desc="Event Bridge"/>
<Value id="eventbridge" desc="Event Bridge"/>
<Value id="http" desc="Http"/>
</Values>
<Options>
<Option type="Required"/>
Expand Down
4 changes: 3 additions & 1 deletion src/AWSLambdaFunctions/createpackage.msbuild
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Deploy" ToolsVersion="4.0">
<PropertyGroup>
<GXDeployFileProject>$([System.IO.Path]::GetFullPath('$(DeployFullPath)\..\..\..\..\web\$(ProjectName).gxdproj'))</GXDeployFileProject>
<ApplicationType>Function</ApplicationType>
<ApplicationType Condition="'$(AWSLAMBDA_FUNCTION_TRIGGER_TYPE)' == 'http'">Web</ApplicationType>
<ApplicationType Condition="'$(AWSLAMBDA_FUNCTION_TRIGGER_TYPE)' != 'http'">Function</ApplicationType>
<LambdaSourceDir>$(DeployFullPath)</LambdaSourceDir>
<LambdaOutputFile>$(DeployFullPath)\AWS_Lambda_Package.zip</LambdaOutputFile>
<SupportLib>$(GX_PROGRAM_DIR)\DeploymentTargets\AWSLambdaFunctions\modules\jdk11</SupportLib>
<SupportLib Condition="'$(ApplicationType)' == 'Web'">$(GX_PROGRAM_DIR)\DeploymentTargets\AWSServerless\modules\jdk8</SupportLib>
</PropertyGroup>

<Import Project="$(GX_PROGRAM_DIR)\GeneXus.AWS.targets"/>
Expand Down
15 changes: 8 additions & 7 deletions src/AWSLambdaFunctions/deploy.msbuild
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
<PackageName>$(JAVA_PACKAGE_NAME)</PackageName>
<GXDeployFileProject>$([System.IO.Path]::GetFullPath('$(DeployFullPath)\..\..\..\..\web\$(ProjectName).gxdproj'))</GXDeployFileProject>
<LambdaOutputFile>$(DEPLOY_PATH)\AWS_Lambda_Package.zip</LambdaOutputFile>

<LambdaHandlerClassName Condition="$(AWSLAMBDA_FUNCTION_TRIGGER_TYPE) == 'queue'">com.genexus.cloud.serverless.aws.handler.LambdaSQSHandler::handleRequest</LambdaHandlerClassName>
<LambdaHandlerClassName Condition="$(AWSLAMBDA_FUNCTION_TRIGGER_TYPE) == 'eventbridge' OR $(AWSLAMBDA_FUNCTION_TRIGGER_TYPE) == 'timer'">com.genexus.cloud.serverless.aws.handler.LambdaEventBridgeHandler::handleRequest</LambdaHandlerClassName>

<LambdaJavaNamespace>com.genexus.cloud.serverless.aws.handler</LambdaJavaNamespace>
<LambdaJavaHandlerName>handleRequest</LambdaJavaHandlerName>
<LambdaHandlerClassName Condition="$(AWSLAMBDA_FUNCTION_TRIGGER_TYPE) == 'http'">$(LambdaJavaNamespace).LambdaHttpApiHandler::$(LambdaJavaHandlerName)</LambdaHandlerClassName>
<LambdaHandlerClassName Condition="$(AWSLAMBDA_FUNCTION_TRIGGER_TYPE) == 'queue'">$(LambdaJavaNamespace).LambdaSQSHandler::$(LambdaJavaHandlerName)</LambdaHandlerClassName>
<LambdaHandlerClassName Condition="$(AWSLAMBDA_FUNCTION_TRIGGER_TYPE) == 'eventbridge' OR $(AWSLAMBDA_FUNCTION_TRIGGER_TYPE) == 'timer'">$(LambdaJavaNamespace).LambdaEventBridgeHandler::$(LambdaJavaHandlerName)</LambdaHandlerClassName>
<AWSCredentialsEnvVars Condition="'$(AWSLAMBDA_PROFILE_NAME)' == ''">AWS_ACCESS_KEY_ID=$(AWSLAMBDA_ACCESS_KEY_ID);AWS_SECRET_ACCESS_KEY=$(AWSLAMBDA_SECRET_ACCESS_KEY);AWS_REGION=$(AWSLAMBDA_DEFAULT_REGION)</AWSCredentialsEnvVars>
<AWSCredentialsEnvVars Condition="'$(AWSLAMBDA_PROFILE_NAME)' != ''">AWS_PROFILE=$(AWSLAMBDA_PROFILE_NAME);</AWSCredentialsEnvVars>
<LambdaUpdateConfiguration>true</LambdaUpdateConfiguration>
Expand All @@ -25,7 +26,7 @@
<AllObjects Include="$(ObjectNames.ToLower().Replace(`procedure:`, ``).Split(`;`))"/>
</ItemGroup>

<Target Name="ValidateDeploySettings">
<Target Name="ValidateDeploySettings">
<Error
Text="AWS Lambda deployment failed: AWS Credentials are missing. Please use AWS Profile Name or Custom Access Key (Access Key ID and Secret Key)"
Condition="$(AWSLAMBDA_PROFILE_NAME) == '' And ($(AWSLAMBDA_ACCESS_KEY_ID) == '' Or $(AWSLAMBDA_SECRET_ACCESS_KEY) == '')"/>
Expand Down Expand Up @@ -79,11 +80,11 @@
--handler $(LambdaHandlerClassName)"
EnvironmentVariables="$(AWSCredentialsEnvVars)"
Condition="'$(LambdaUpdateConfiguration)' == 'true'"/>

<Message
Text="Lambda source Mapping ($(AWSLAMBDA_FUNCTION_TRIGGER_TYPE)) must be added in the Lambda Console UI"
Importance="High"
Condition="$(AWSLAMBDA_FUNCTION_TRIGGER_TYPE) != ''"/>
Condition="$(AWSLAMBDA_FUNCTION_TRIGGER_TYPE) != '' AND $(AWSLAMBDA_FUNCTION_TRIGGER_TYPE) != 'http'"/>

<Message Text="Lambda Function '$(AWSLAMBDA_FUNCTION_NAME)' deployed successfully. ARN: '$(LambdaARN)'" Importance="High" />
</Target>
Expand Down
12 changes: 9 additions & 3 deletions src/AWSLambdaFunctions/lambda.targets
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<ItemGroup>
<AllSelectedObjects Include="@(Object->HasMetadata('Selected')->WithMetadataValue('Selected','true'))" />
<AllSelectedObjects Include="@(Object->HasMetadata('Selected')->WithMetadataValue('Selected','true'))" />
<AllRestObjects Include="@(Object->HasMetadata('IsRest')->WithMetadataValue('IsRest','true'))" />
</ItemGroup>

<Target Name="ValidateDeployment" Inputs="@(Object)" Outputs="%(Object.Identity)">
<Error Text="AWS LambdaFunctions deployment failed: Select only one main procedure." Condition="'@(AllSelectedObjects->Count())' != 1" />
<Error Text="AWS LambdaFunctions deployment failed: Select only one main procedure."
Condition="'@(AllSelectedObjects->Count())' != 1 AND $(AWSLAMBDA_FUNCTION_TRIGGER_TYPE) != 'http'" />

<Error Text="AWS LambdaFunctions deployment failed: '%(Object.Identity)' is not a Procedure. Only GX Procedures can be deployed to AWSLambda as Functions." Condition="%(Object.Type) != 'Procedure' AND %(Object.Type) != 'File' AND %(Object.Selected) == 'true' " />
<Error Text="AWS LambdaFunctions deployment failed: '%(Object.Identity)' is not a Procedure. Only GX Procedures can be deployed to AWSLambda as Functions."
Condition="$(AWSLAMBDA_FUNCTION_TRIGGER_TYPE) != 'http' AND %(Object.Type) != 'Procedure' AND %(Object.Type) != 'File' AND %(Object.Selected) == 'true' " />

<Error Text="AWS LambdaFunctions deployment failed: Deployment must include one or more REST Service (Expose As Rest Service = True OR APIObjects)."
Condition="'@(AllRestObjects->Count())' == 0 AND $(AWSLAMBDA_FUNCTION_TRIGGER_TYPE) == 'http'"/>
</Target>
</Project>
2 changes: 2 additions & 0 deletions src/Common/AWS/awslambda-create-package.targets
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
</Target>

<Target Name="PreValidate" >
<Message Text="Start Lambda Create Package for $(ApplicationType)" Importance="high"/>
<PropertyGroup>
<!-- ApplicationType Web or Function -->
<!-- SupportLib -->
Expand Down Expand Up @@ -49,6 +50,7 @@
<ConfigFiles Include="$(LambdaSourceDir)/**/log4j2.xml"/>
<ConfigFiles Include="$(LambdaSourceDir)/**/*.services"/>
<ConfigFiles Include="$(LambdaSourceDir)/**/*.gam"/>
<ConfigFiles Include="$(LambdaSourceDir)/**/*.ini"/>
<ConfigFiles Include="$(ClassesDir)/*.*"/>

<GAMConfigFiles Include="$(LambdaSourceDir)/**/*.gam"/>
Expand Down