Skip to content

Commit

Permalink
feat: lambda dotnet 8 support (#14026)
Browse files Browse the repository at this point in the history
* feat: lambda dotnet 8 support

* chore: update tests

* chore: one more test

* chore: lint

* chore: test pin node version

* chore: test with skip prompts for node install

* chore: move -y flag

* chore: switch to nodejs-lts with version

* chore: revert changes to build windows

* chore: remove ls of restricted dir

* chore: remove use of /Users/aluja in windows

* chore: try with /root

* chore: remove unneeded jq install

* chore: update /Users/aluja to be actual value

* chore: remove duplicate code for loading aws profile

* chore: fix test
  • Loading branch information
awsluja authored Dec 10, 2024
1 parent b8b6498 commit 540bfe1
Show file tree
Hide file tree
Showing 23 changed files with 53 additions and 60 deletions.
1 change: 0 additions & 1 deletion codebuild_specs/run_e2e_tests_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ env:
phases:
build:
commands:
- choco install -fy jq
- git config --global core.longpaths true
- bash ./codebuild_specs/scripts-windows/load-e2e-cache.sh
- bash ./codebuild_specs/scripts-windows/rename-packaged-cli.sh
Expand Down
7 changes: 2 additions & 5 deletions codebuild_specs/scripts-windows/shared-scripts-windows.sh
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,6 @@ function _loadTestAccountCredentials {
function _lsOut {
ls ..
ls ~
ls $HOME
ls $HOME/..
ls $HOME/../..
}
function _build {
echo Windows Build
Expand All @@ -120,8 +117,8 @@ function _install_packaged_cli_win {
echo Move to CLI Binary to already existing PATH
# This is a Hack to make sure the Amplify CLI is in the PATH

cp $CODEBUILD_SRC_DIR/out/amplify.exe $HOME/AppData/Local/Microsoft/WindowsApps
ls $HOME/AppData/Local/Microsoft/WindowsApps
cp $CODEBUILD_SRC_DIR/out/amplify.exe C:/Users/ContainerAdministrator/AppData/Local/Microsoft/WindowsApps
ls C:/Users/ContainerAdministrator/AppData/Local/Microsoft/WindowsApps

# reset working directory
cd $CODEBUILD_SRC_DIR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
},
"runtimes": [
{
"name": ".NET 6",
"value": "dotnet6"
"name": ".NET 8",
"value": "dotnet8"
}
]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export const currentSupportedVersion = '6.0';
export const dotnet6 = 'dotnet6';
// see https://aws.amazon.com/blogs/compute/introducing-the-net-8-runtime-for-aws-lambda
// https://docs.aws.amazon.com/lambda/latest/dg/lambda-csharp.html
export const currentSupportedVersion = '8.0';
export const dotnet8 = 'dotnet8';
export const handlerMethodName = 'LambdaHandler';
export const executableName = 'dotnet';
12 changes: 6 additions & 6 deletions packages/amplify-dotnet-function-runtime-provider/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FunctionRuntimeContributorFactory } from '@aws-amplify/amplify-function-plugin-interface';
import { dotnet6 } from './constants';
import { dotnet8 } from './constants';
import { detectDotNet } from './utils/detect';
import { build } from './utils/build';
import { packageAssemblies } from './utils/package';
Expand All @@ -10,14 +10,14 @@ export const functionRuntimeContributorFactory: FunctionRuntimeContributorFactor
checkDependencies: detectDotNet,
contribute: async (contributionRequest) => {
switch (contributionRequest.selection) {
case dotnet6:
case dotnet8:
return {
runtime: {
name: '.NET 6',
value: dotnet6,
cloudTemplateValue: dotnet6,
name: '.NET 8',
value: dotnet8,
cloudTemplateValue: dotnet8,
defaultHandler: `${contributionRequest.contributionContext.resourceName}::${contributionRequest.contributionContext.resourceName}.${contributionRequest.contributionContext.functionName}::LambdaHandler`,
layerExecutablePath: dotnet6,
layerExecutablePath: dotnet8,
},
};
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const detectDotNet = async (): Promise<CheckDependenciesResult> => {
if (sdkResult.exitCode !== 0) {
throw new Error(`${executableName} failed SDK detection, exit code was ${sdkResult.exitCode}`);
}
const requiredSdkRegex = /^6\.0/m;
const requiredSdkRegex = /^8\.0/m;
const sdkInstalled = installedSdks && installedSdks.match(requiredSdkRegex);

const toolResult = execa.sync(executableName, ['tool', 'list', '--global']);
Expand All @@ -37,13 +37,13 @@ export const detectDotNet = async (): Promise<CheckDependenciesResult> => {
if (installedToolList.match(/^amazon\.lambda\.tools/m)) {
toolInstalled = true;
}
const requiredTestToolVersionRegex = /^amazon\.lambda\.testtool-6\.0/m;
const requiredTestToolVersionRegex = /^amazon\.lambda\.testtool-8\.0/m;
if (installedToolList.match(requiredTestToolVersionRegex)) {
testToolInstalled = true;
}
}

// Verify that a dotnet 6 SDK and the dotnet Lambda tools is installed locally
// Verify that a dotnet 8 SDK and the dotnet Lambda tools is installed locally
if (sdkInstalled && toolInstalled && testToolInstalled) {
return {
hasRequiredDependencies: true,
Expand All @@ -54,15 +54,15 @@ export const detectDotNet = async (): Promise<CheckDependenciesResult> => {
errorMessage: 'Unable to detect required dependencies:\n',
};
if (!sdkInstalled) {
result.errorMessage += '- The .NET 6 SDK must be installed. It can be installed from https://dotnet.microsoft.com/download\n';
result.errorMessage += '- The .NET 8 SDK must be installed. It can be installed from https://dotnet.microsoft.com/download\n';
}
if (!toolInstalled) {
result.errorMessage +=
'- The Amazon.Lambda.Tools global tool must be installed. Please install by running "dotnet tool install -g Amazon.Lambda.Tools".\n';
}
if (!testToolInstalled) {
result.errorMessage +=
'- The Amazon.Lambda.TestTool-6.0 global tool must be installed. Please install by running "dotnet tool install -g Amazon.Lambda.TestTool-6.0".\n';
'- The Amazon.Lambda.TestTool-8.0 global tool must be installed. Please install by running "dotnet tool install -g Amazon.Lambda.TestTool-8.0".\n';
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const invoke = async (request: InvocationRequest): Promise<string> => {
tempDir = fs.mkdtempSync(path.join(request.srcRoot, 'amplify'));
eventFile = path.join(tempDir, 'event.json');
fs.writeFileSync(eventFile, request.event);
const lambdaTestTool = 'lambda-test-tool-6.0';
const lambdaTestTool = 'lambda-test-tool-8.0';
const execPromise = execa(
executableName,
[lambdaTestTool, '--no-ui', '--function-handler', request.handler, '--payload', eventFile, '--pause-exit', 'false'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const packageAssemblies = async (request: PackageRequest, context: any):
}

const packageHash = (await context.amplify.hashDir(distPath, [])) as string;
const framework = 'net6.0';
const framework = 'net8.0';
try {
const result = execa.sync(
executableName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"conditions": {
"provider": "awscloudformation",
"services": ["Lambda"],
"runtime": ["dotnet6"]
"runtime": ["dotnet8"]
},
"templates": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<AWSProjectType>Lambda</AWSProjectType>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
"profile":"",
"region" : "",
"configuration" : "Release",
"framework" : "net6.0",
"framework" : "net8.0",
"function-runtime":"props.runtime.value",
"function-memory-size" : 256,
"function-memory-size" : 512,
"function-timeout" : 30,
"function-handler" : "<%= props.resourceName %>::<%= props.resourceName %>.<%= props.functionName %>::LambdaHandler"
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<AWSProjectType>Lambda</AWSProjectType>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
"profile":"",
"region" : "",
"configuration" : "Release",
"framework" : "net6.0",
"framework" : "net8.0",
"function-runtime":"props.runtime.value",
"function-memory-size" : 256,
"function-memory-size" : 512,
"function-timeout" : 30,
"function-handler" : "<%= props.resourceName %>::<%= props.resourceName %>.<%= props.functionName %>::LambdaHandler"
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<AWSProjectType>Lambda</AWSProjectType>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
"profile":"",
"region" : "",
"configuration" : "Release",
"framework" : "net6.0",
"framework" : "net8.0",
"function-runtime":"props.runtime.value",
"function-memory-size" : 256,
"function-memory-size" : 512,
"function-timeout" : 30,
"function-handler" : "<%= props.resourceName %>::<%= props.resourceName %>.<%= props.functionName %>::LambdaHandler"
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<AWSProjectType>Lambda</AWSProjectType>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
"profile":"",
"region" : "",
"configuration" : "Release",
"framework" : "net6.0",
"framework" : "net8.0",
"function-runtime":"props.runtime.value",
"function-memory-size" : 256,
"function-memory-size" : 512,
"function-timeout" : 30,
"function-handler" : "<%= props.resourceName %>::<%= props.resourceName %>.<%= props.functionName %>::LambdaHandler"
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "6.0.100",
"version": "8.0.404",
"rollForward": "latestFeature"
}
}
10 changes: 5 additions & 5 deletions packages/amplify-e2e-core/src/categories/lambda-function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import _ from 'lodash';
import { loadFeatureFlags } from '../utils/feature-flags';
type FunctionActions = 'create' | 'update';

type FunctionRuntimes = 'dotnet6' | 'go' | 'java' | 'nodejs' | 'python';
type FunctionRuntimes = 'dotnet8' | 'go' | 'java' | 'nodejs' | 'python';

type FunctionCallback = (chain: any, cwd: string, settings: any) => any;

// runtimeChoices are shared between tests
export const runtimeChoices = ['.NET 6', 'Go', 'Java', 'NodeJS', 'Python'];
export const runtimeChoices = ['.NET 8', 'Go', 'Java', 'NodeJS', 'Python'];

// templateChoices is per runtime
const dotNetTemplateChoices = [
Expand Down Expand Up @@ -655,7 +655,7 @@ export const functionCloudInvoke = async (

const getTemplateChoices = (runtime: FunctionRuntimes) => {
switch (runtime) {
case 'dotnet6':
case 'dotnet8':
return dotNetTemplateChoices;
case 'go':
return goTemplateChoices;
Expand All @@ -672,8 +672,8 @@ const getTemplateChoices = (runtime: FunctionRuntimes) => {

const getRuntimeDisplayName = (runtime: FunctionRuntimes) => {
switch (runtime) {
case 'dotnet6':
return '.NET 6';
case 'dotnet8':
return '.NET 8';
case 'go':
return 'Go';
case 'java':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('dotnet function tests', () => {
name: funcName,
functionTemplate: 'Hello World',
},
'dotnet6',
'dotnet8',
);
});

Expand Down
16 changes: 8 additions & 8 deletions packages/amplify-e2e-tests/src/__tests__/function_3b.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ describe('dotnet function tests', () => {
const assertDotNetVersion = (): void => {
const functionPath = pathManager.getResourceDirectoryPath(projRoot, AmplifyCategories.FUNCTION, funcName);
const { functionRuntime } = JSONUtilities.readJson<any>(path.join(functionPath, 'amplify.state'));
expect(functionRuntime).toEqual('dotnet6');
expect(functionRuntime).toEqual('dotnet8');
const functionProjFilePath = path.join(functionPath, 'src', `${funcName}.csproj`);
const functionProjFileContent = fs.readFileSync(functionProjFilePath, 'utf8');
expect(functionProjFileContent).toContain('<TargetFramework>net6.0</TargetFramework>');
expect(functionProjFileContent).toContain('<TargetFramework>net8.0</TargetFramework>');
};

it('add dotnet hello world function and mock locally', async () => {
Expand All @@ -56,7 +56,7 @@ describe('dotnet function tests', () => {
name: funcName,
functionTemplate: 'Hello World',
},
'dotnet6',
'dotnet8',
);
await functionMockAssert(projRoot, {
funcName,
Expand All @@ -74,7 +74,7 @@ describe('dotnet function tests', () => {
name: funcName,
functionTemplate: 'Hello World',
},
'dotnet6',
'dotnet8',
);
const payload = '{"key1":"value1","key2":"value2","key3":"value3"}';
await amplifyPushAuth(projRoot);
Expand All @@ -91,7 +91,7 @@ describe('dotnet function tests', () => {
name: funcName,
functionTemplate: 'Serverless',
},
'dotnet6',
'dotnet8',
);
await functionMockAssert(projRoot, {
funcName,
Expand All @@ -109,7 +109,7 @@ describe('dotnet function tests', () => {
name: funcName,
functionTemplate: 'CRUD function for DynamoDB (Integration with API Gateway)',
},
'dotnet6',
'dotnet8',
createNewDynamoDBForCrudTemplate,
);
const payload = JSON.stringify({
Expand All @@ -135,7 +135,7 @@ describe('dotnet function tests', () => {
triggerType: 'DynamoDB',
eventSource: 'DynamoDB',
},
'dotnet6',
'dotnet8',
addLambdaTrigger, // Adds DDB trigger by default
);
await functionMockAssert(projRoot, {
Expand All @@ -156,7 +156,7 @@ describe('dotnet function tests', () => {
functionTemplate: 'Trigger (DynamoDb, Kinesis)',
triggerType: 'Kinesis',
},
'dotnet6',
'dotnet8',
addLambdaTrigger, // Adds DDB trigger by default
);
await functionMockAssert(projRoot, {
Expand Down
5 changes: 0 additions & 5 deletions packages/amplify-e2e-tests/src/__tests__/import_s3_3.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import {
getS3ResourceName,
} from '../import-helpers';

const profileName = 'amplify-integ-test-user';

describe('headless s3 import', () => {
const projectPrefix = 'sssheadimp';
const bucketPrefix = 'sss-headless-import-test';
Expand All @@ -38,9 +36,6 @@ describe('headless s3 import', () => {
const shortId = getShortId();
bucketNameToImport = `${bucketPrefix}${shortId}`;

const credentials = new aws.SharedIniFileCredentials({ profile: profileName });
aws.config.credentials = credentials;

const s3 = new aws.S3();

await s3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import _ from 'lodash';

type FunctionActions = 'create' | 'update';
type FunctionRuntimes = 'dotnet6' | 'go' | 'java' | 'nodejs' | 'python';
type FunctionRuntimes = 'dotnet8' | 'go' | 'java' | 'nodejs' | 'python';
type FunctionCallback = (chain: $TSAny, cwd: string, settings: $TSAny) => $TSAny;

// runtimeChoices are shared between tests
Expand Down Expand Up @@ -507,7 +507,7 @@ const addCron = (chain: ExecutionContext, settings: $TSAny) => {

const getTemplateChoices = (runtime: FunctionRuntimes) => {
switch (runtime) {
case 'dotnet6':
case 'dotnet8':
return dotNetTemplateChoices;
case 'go':
return goTemplateChoices;
Expand All @@ -524,8 +524,8 @@ const getTemplateChoices = (runtime: FunctionRuntimes) => {

const getRuntimeDisplayName = (runtime: FunctionRuntimes) => {
switch (runtime) {
case 'dotnet6':
return '.NET 6';
case 'dotnet8':
return '.NET 8';
case 'go':
return 'Go';
case 'java':
Expand Down

0 comments on commit 540bfe1

Please sign in to comment.