-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add a .NET Core 2.0 Hello World sample #377
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
Closed
Closed
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
dee54f4
Add dotnetcore2.0 hello world lambda
joaoasrosa 6fa5e2a
Add Cake and SAM Local artifacts
joaoasrosa a8f4dfa
Add README
joaoasrosa a91d79f
Update samples README
joaoasrosa 147068c
Update README
joaoasrosa 249e584
Fix bug in the Default Cake task.
joaoasrosa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| | ||
| Microsoft Visual Studio Solution File, Format Version 12.00 | ||
| Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{15BADD3C-EB9E-4027-83A8-4164B0FD0B94}" | ||
| EndProject | ||
| Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloWorld", "src\HelloWorld\HelloWorld.csproj", "{1C72B9A4-F5C5-4019-BF0F-CC10BDECF582}" | ||
| EndProject | ||
| Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{7C692A39-E2E3-4170-AB91-86BD226D61D7}" | ||
| ProjectSection(SolutionItems) = preProject | ||
| build.cake = build.cake | ||
| build.ps1 = build.ps1 | ||
| build.sh = build.sh | ||
| event.json = event.json | ||
| template.yml = template.yml | ||
| EndProjectSection | ||
| EndProject | ||
| Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{F090076F-EE78-4CC6-B614-9069D413A885}" | ||
| ProjectSection(SolutionItems) = preProject | ||
| README.md = README.md | ||
| EndProjectSection | ||
| EndProject | ||
| Global | ||
| GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
| Debug|Any CPU = Debug|Any CPU | ||
| Release|Any CPU = Release|Any CPU | ||
| EndGlobalSection | ||
| GlobalSection(NestedProjects) = preSolution | ||
| {1C72B9A4-F5C5-4019-BF0F-CC10BDECF582} = {15BADD3C-EB9E-4027-83A8-4164B0FD0B94} | ||
| EndGlobalSection | ||
| GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
| {1C72B9A4-F5C5-4019-BF0F-CC10BDECF582}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
| {1C72B9A4-F5C5-4019-BF0F-CC10BDECF582}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
| {1C72B9A4-F5C5-4019-BF0F-CC10BDECF582}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
| {1C72B9A4-F5C5-4019-BF0F-CC10BDECF582}.Release|Any CPU.Build.0 = Release|Any CPU | ||
| EndGlobalSection | ||
| EndGlobal |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| # AWS SAM Hello World Example # | ||
|
|
||
| A simple AWS SAM template that specifies a single Lambda function. | ||
|
|
||
| ## Usage ## | ||
|
|
||
| To create and deploy the SAM Hello World example, first ensure that you've met the requirements described in the [root README](../../README.md). Then follow the steps below. | ||
|
|
||
| ### Build your package ### | ||
|
|
||
| #### Linux & macOS | ||
|
|
||
| sh build.sh --target=Package | ||
|
|
||
| #### Windows (Powershell) | ||
|
|
||
| build.ps1 --target=Package | ||
|
|
||
| ### Test your application locally ### | ||
|
|
||
| Use [SAM Local](https://github.com/awslabs/aws-sam-local) to run your Lambda function locally: | ||
|
|
||
| sam local invoke "HelloWorld" -e event.json | ||
|
|
||
| ### Package artifacts ### | ||
|
|
||
| Run the following command, replacing `BUCKET-NAME` with the name of your bucket: | ||
|
|
||
| sam package --template-file template.yaml --s3-bucket BUCKET-NAME --output-template-file packaged-template.yaml | ||
|
|
||
| This creates a new template file, packaged-template.yaml, that you will use to deploy your serverless application. | ||
|
|
||
| ### Deploy to AWS CloudFormation ### | ||
|
|
||
| Run the following command, replacing `MY-NEW-STACK` with a name for your CloudFormation stack. | ||
|
|
||
| sam deploy --template-file packaged-template.yaml --stack-name MY-NEW-STACK --capabilities CAPABILITY_IAM | ||
|
|
||
| This uploads your template to an S3 bucket and deploys the specified resources using AWS CloudFormation. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,231 @@ | ||
| /////////////////////////////////////////////////////////////////////////////// | ||
| // ARGUMENTS | ||
| /////////////////////////////////////////////////////////////////////////////// | ||
|
|
||
| var target = Argument<string>("target", "Default"); | ||
| var configuration = Argument<string>("configuration", "Release"); | ||
| var verbosity = Argument<string>("verbosity", "Minimal"); | ||
|
|
||
| /////////////////////////////////////////////////////////////////////////////// | ||
| // GLOBAL VARIABLES | ||
| /////////////////////////////////////////////////////////////////////////////// | ||
|
|
||
| var sourceDir = Directory("./src"); | ||
|
|
||
| var solutions = GetFiles("./**/*.sln"); | ||
| var projects = new [] | ||
| { | ||
| sourceDir.Path + "/HelloWorld/HelloWorld.csproj", | ||
| }; | ||
|
|
||
| // BUILD OUTPUT DIRECTORIES | ||
| var artifactsDir = Directory("./artifacts"); | ||
| var publishDir = Directory("./publish/"); | ||
|
|
||
| // VERBOSITY | ||
| var dotNetCoreVerbosity = Cake.Common.Tools.DotNetCore.DotNetCoreVerbosity.Normal; | ||
| if (!Enum.TryParse(verbosity, true, out dotNetCoreVerbosity)) | ||
| { | ||
| dotNetCoreVerbosity = Cake.Common.Tools.DotNetCore.DotNetCoreVerbosity.Normal; | ||
| Warning( | ||
| "Verbosity could not be parsed into type 'Cake.Common.Tools.DotNetCore.DotNetCoreVerbosity'. Defaulting to {0}", | ||
| dotNetCoreVerbosity); | ||
| } | ||
|
|
||
| /////////////////////////////////////////////////////////////////////////////// | ||
| // COMMON FUNCTION DEFINITIONS | ||
| /////////////////////////////////////////////////////////////////////////////// | ||
|
|
||
| string GetProjectName(string project) | ||
| { | ||
| return project | ||
| .Split(new [] {'/'}, StringSplitOptions.RemoveEmptyEntries) | ||
| .Last() | ||
| .Replace(".csproj", string.Empty); | ||
| } | ||
|
|
||
| /////////////////////////////////////////////////////////////////////////////// | ||
| // SETUP / TEARDOWN | ||
| /////////////////////////////////////////////////////////////////////////////// | ||
|
|
||
| Setup(ctx => | ||
| { | ||
| // Executed BEFORE the first task. | ||
| EnsureDirectoryExists(artifactsDir); | ||
| EnsureDirectoryExists(publishDir); | ||
| Information("Running tasks..."); | ||
| }); | ||
|
|
||
| Teardown(ctx => | ||
| { | ||
| // Executed AFTER the last task. | ||
| Information("Finished running tasks."); | ||
| }); | ||
|
|
||
| /////////////////////////////////////////////////////////////////////////////// | ||
| // TASK DEFINITIONS | ||
| /////////////////////////////////////////////////////////////////////////////// | ||
|
|
||
| Task("Clean") | ||
| .Description("Cleans all directories that are used during the build process.") | ||
| .Does(() => | ||
| { | ||
| foreach(var solution in solutions) | ||
| { | ||
| Information("Cleaning {0}", solution.FullPath); | ||
| CleanDirectories(solution.FullPath + "/**/bin/" + configuration); | ||
| CleanDirectories(solution.FullPath + "/**/obj/" + configuration); | ||
| Information("{0} was clean.", solution.FullPath); | ||
| } | ||
|
|
||
| CleanDirectory(artifactsDir); | ||
| CleanDirectory(publishDir); | ||
| }); | ||
|
|
||
| Task("Restore") | ||
| .Description("Restores all the NuGet packages that are used by the specified solution.") | ||
| .Does(() => | ||
| { | ||
| var settings = new DotNetCoreRestoreSettings | ||
| { | ||
| DisableParallel = false, | ||
| NoCache = true, | ||
| Verbosity = dotNetCoreVerbosity | ||
| }; | ||
|
|
||
| foreach(var solution in solutions) | ||
| { | ||
| Information("Restoring NuGet packages for '{0}'...", solution); | ||
| DotNetCoreRestore(solution.FullPath, settings); | ||
| Information("NuGet packages restored for '{0}'.", solution); | ||
| } | ||
| }); | ||
|
|
||
| Task("Build") | ||
| .Description("Builds all the different parts of the project.") | ||
| .Does(() => | ||
| { | ||
| var msBuildSettings = new DotNetCoreMSBuildSettings | ||
| { | ||
| TreatAllWarningsAs = MSBuildTreatAllWarningsAs.Error, | ||
| Verbosity = dotNetCoreVerbosity | ||
| }; | ||
|
|
||
| var settings = new DotNetCoreBuildSettings | ||
| { | ||
| Configuration = configuration, | ||
| MSBuildSettings = msBuildSettings, | ||
| NoRestore = true | ||
| }; | ||
|
|
||
| foreach(var solution in solutions) | ||
| { | ||
| Information("Building '{0}'...", solution); | ||
| DotNetCoreBuild(solution.FullPath, settings); | ||
| Information("'{0}' has been built.", solution); | ||
| } | ||
| }); | ||
|
|
||
| Task("Publish") | ||
| .Description("Publish the Lambda Functions.") | ||
| .Does(() => | ||
| { | ||
| foreach(var project in projects) | ||
| { | ||
| var projectName = project | ||
| .Split(new [] {'/'}, StringSplitOptions.RemoveEmptyEntries) | ||
| .Last() | ||
| .Replace(".csproj", string.Empty); | ||
|
|
||
| var outputDirectory = System.IO.Path.Combine(publishDir, projectName); | ||
|
|
||
| var msBuildSettings = new DotNetCoreMSBuildSettings | ||
| { | ||
| TreatAllWarningsAs = MSBuildTreatAllWarningsAs.Error, | ||
| Verbosity = dotNetCoreVerbosity | ||
| }; | ||
|
|
||
| var settings = new DotNetCorePublishSettings | ||
| { | ||
| Configuration = configuration, | ||
| MSBuildSettings = msBuildSettings, | ||
| NoRestore = true, | ||
| OutputDirectory = outputDirectory, | ||
| Verbosity = dotNetCoreVerbosity | ||
| }; | ||
|
|
||
| Information("Publishing '{0}'...", projectName); | ||
| DotNetCorePublish(project, settings); | ||
| Information("'{0}' has been published.", projectName); | ||
| } | ||
| }); | ||
|
|
||
| Task("Pack") | ||
| .Description("Packs all the different parts of the project.") | ||
| .Does(() => | ||
| { | ||
| foreach(var project in projects) | ||
| { | ||
| var projectName = GetProjectName(project); | ||
|
|
||
| Information("Packing '{0}'...", projectName); | ||
| var path = System.IO.Path.Combine(publishDir, projectName); | ||
| var files = GetFiles(path + "/*.*"); | ||
| Zip( | ||
| path, | ||
| System.IO.Path.Combine(artifactsDir, $"{projectName}.zip"), | ||
| files); | ||
| Information("'{0}' has been packed.", projectName); | ||
| } | ||
| }); | ||
|
|
||
| Task("Run-Local") | ||
| .Description("Runs all the acceptance tests locally.") | ||
| .Does(() => | ||
| { | ||
| var settings = new ProcessSettings | ||
| { | ||
| Arguments = "local invoke \"HelloWorld\" -e event.json", | ||
| }; | ||
|
|
||
| Information("Starting the SAM local..."); | ||
| using(var process = StartAndReturnProcess("sam", settings)) | ||
| { | ||
| process.WaitForExit(); | ||
| Information("Exit code: {0}", process.GetExitCode()); | ||
| } | ||
| Information("SAM local has finished."); | ||
| }); | ||
|
|
||
| /////////////////////////////////////////////////////////////////////////////// | ||
| // TARGETS | ||
| /////////////////////////////////////////////////////////////////////////////// | ||
|
|
||
| Task("Package") | ||
| .Description("This is the task which will run if target Package is passed in.") | ||
| .IsDependentOn("Clean") | ||
| .IsDependentOn("Restore") | ||
| .IsDependentOn("Build") | ||
| .IsDependentOn("Publish") | ||
| .IsDependentOn("Pack") | ||
| .Does(() => { Information("Package target ran."); }); | ||
|
|
||
| Task("Run") | ||
| .Description("This is the task which will run if target Run is passed in.") | ||
| .IsDependentOn("Clean") | ||
| .IsDependentOn("Restore") | ||
| .IsDependentOn("Build") | ||
| .IsDependentOn("Publish") | ||
| .IsDependentOn("Pack") | ||
| .IsDependentOn("Run-Local") | ||
| .Does(() => { Information("Run target ran."); }); | ||
|
|
||
| Task("Default") | ||
| .Description("This is the default task which will run if no specific target is passed in.") | ||
| .IsDependentOn("Default"); | ||
|
|
||
| /////////////////////////////////////////////////////////////////////////////// | ||
| // EXECUTION | ||
| /////////////////////////////////////////////////////////////////////////////// | ||
|
|
||
| RunTarget(target); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This causes a
Reflexive edges in graph are not allowedexception (the task being dependant on itself).