diff --git a/samcli/local/init/__init__.py b/samcli/local/init/__init__.py index 8ef8c8dd26..31d63a6f37 100644 --- a/samcli/local/init/__init__.py +++ b/samcli/local/init/__init__.py @@ -28,6 +28,7 @@ "dotnetcore1.0": os.path.join(_templates, "cookiecutter-aws-sam-hello-dotnet"), "dotnetcore": os.path.join(_templates, "cookiecutter-aws-sam-hello-dotnet"), "dotnet": os.path.join(_templates, "cookiecutter-aws-sam-hello-dotnet"), + "powershell": os.path.join(_templates, "cookiecutter-aws-sam-hello-powershell"), "go1.x": os.path.join(_templates, "cookiecutter-aws-sam-hello-golang"), "go": os.path.join(_templates, "cookiecutter-aws-sam-hello-golang"), "java8": os.path.join(_templates, "cookiecutter-aws-sam-hello-java"), diff --git a/samcli/local/init/templates/cookiecutter-aws-sam-hello-powershell/.gitignore b/samcli/local/init/templates/cookiecutter-aws-sam-hello-powershell/.gitignore new file mode 100644 index 0000000000..31d2b18851 --- /dev/null +++ b/samcli/local/init/templates/cookiecutter-aws-sam-hello-powershell/.gitignore @@ -0,0 +1,174 @@ + +# Created by https://www.gitignore.io/api/osx,linux,python,windows + +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### OSX ### +*.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### Python ### +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +.pytest_cache/ +nosetests.xml +coverage.xml +*.cover +.hypothesis/ + +# Translations +*.mo +*.pot + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule.* + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +ehthumbs.db +ehthumbs_vista.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# Exclude packaged modules +*.zip + +# Exclude .NET assemblies from source +*.dll + + +# End of https://www.gitignore.io/api/osx,linux,python,windows \ No newline at end of file diff --git a/samcli/local/init/templates/cookiecutter-aws-sam-hello-powershell/LICENSE b/samcli/local/init/templates/cookiecutter-aws-sam-hello-powershell/LICENSE new file mode 100644 index 0000000000..f19aaa6d09 --- /dev/null +++ b/samcli/local/init/templates/cookiecutter-aws-sam-hello-powershell/LICENSE @@ -0,0 +1,14 @@ +MIT No Attribution + +Permission is hereby granted, free of charge, to any person obtaining a copy of this +software and associated documentation files (the "Software"), to deal in the Software +without restriction, including without limitation the rights to use, copy, modify, +merge, publish, distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/samcli/local/init/templates/cookiecutter-aws-sam-hello-powershell/README.md b/samcli/local/init/templates/cookiecutter-aws-sam-hello-powershell/README.md new file mode 100644 index 0000000000..d8b0b5afb1 --- /dev/null +++ b/samcli/local/init/templates/cookiecutter-aws-sam-hello-powershell/README.md @@ -0,0 +1,20 @@ +# Cookiecutter DotNet Core Hello-world for SAM based Serverless App + +A cookiecutter template to create a PowerShell Hello world boilerplate using [Serverless Application Model (SAM)](https://github.com/awslabs/serverless-application-model). + +## Requirements + +* [AWS SAM CLI](https://github.com/awslabs/aws-sam-cli) + +## Usage + +Generate a boilerplate template in your current project directory using the following syntax: + +* **PowerShell**: `sam init --runtime powershell` + +> **NOTE**: ``--name`` allows you to specify a different project folder name (`sam-app` is the default) + + +# Credits + +* This project has been generated with [Cookiecutter](https://github.com/audreyr/cookiecutter) diff --git a/samcli/local/init/templates/cookiecutter-aws-sam-hello-powershell/cookiecutter.json b/samcli/local/init/templates/cookiecutter-aws-sam-hello-powershell/cookiecutter.json new file mode 100644 index 0000000000..8f29fcc426 --- /dev/null +++ b/samcli/local/init/templates/cookiecutter-aws-sam-hello-powershell/cookiecutter.json @@ -0,0 +1,4 @@ +{ + "project_name": "Name of the project", + "runtime": "dotnetcore2.1" +} diff --git a/samcli/local/init/templates/cookiecutter-aws-sam-hello-powershell/setup.cfg b/samcli/local/init/templates/cookiecutter-aws-sam-hello-powershell/setup.cfg new file mode 100644 index 0000000000..eee4ab11a7 --- /dev/null +++ b/samcli/local/init/templates/cookiecutter-aws-sam-hello-powershell/setup.cfg @@ -0,0 +1,2 @@ +[install] +prefix= \ No newline at end of file diff --git a/samcli/local/init/templates/cookiecutter-aws-sam-hello-powershell/{{cookiecutter.project_name}}/.gitignore b/samcli/local/init/templates/cookiecutter-aws-sam-hello-powershell/{{cookiecutter.project_name}}/.gitignore new file mode 100644 index 0000000000..eb557a8e67 --- /dev/null +++ b/samcli/local/init/templates/cookiecutter-aws-sam-hello-powershell/{{cookiecutter.project_name}}/.gitignore @@ -0,0 +1,410 @@ + +# Created by https://www.gitignore.io/api/macos,linux,windows,sublimetext,dotsettings,visualstudio,visualstudiocode + +### DotSettings ### +*.DotSettings +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### macOS ### +*.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### SublimeText ### +# cache files for sublime text +*.tmlanguage.cache +*.tmPreferences.cache +*.stTheme.cache + +# workspace files are user-specific +*.sublime-workspace + +# project files should be checked into the repository, unless a significant +# proportion of contributors will probably not be using SublimeText +# *.sublime-project + +# sftp configuration file +sftp-config.json + +# Package control specific files +Package Control.last-run +Package Control.ca-list +Package Control.ca-bundle +Package Control.system-ca-bundle +Package Control.cache/ +Package Control.ca-certs/ +Package Control.merged-ca-bundle +Package Control.user-ca-bundle +oscrypto-ca-bundle.crt +bh_unicode_properties.cache + +# Sublime-github package stores a github token in this file +# https://packagecontrol.io/packages/sublime-github +GitHub.sublime-settings + +### VisualStudioCode ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +.history + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +ehthumbs.db +ehthumbs_vista.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msm +*.msp + +# Windows shortcuts +*.lnk + +### VisualStudio ### +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ +**/Properties/launchSettings.json + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Uncomment the next line to ignore your web deploy settings. +# By default, sensitive information, such as encrypted password +# should be stored in the .pubxml.user file. +#*.pubxml +*.pubxml.user +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Typescript v1 declaration files +typings/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush +.cr/ + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +### VisualStudio Patch ### +# By default, sensitive information, such as encrypted password +# should be stored in the .pubxml.user file. + +# Exclude packaged modules +*.zip + +# Exclude .NET assemblies from source +*.dll + +# End of https://www.gitignore.io/api/macos,linux,windows,sublimetext,dotsettings,visualstudio,visualstudiocode \ No newline at end of file diff --git a/samcli/local/init/templates/cookiecutter-aws-sam-hello-powershell/{{cookiecutter.project_name}}/README.md b/samcli/local/init/templates/cookiecutter-aws-sam-hello-powershell/{{cookiecutter.project_name}}/README.md new file mode 100644 index 0000000000..433743bd65 --- /dev/null +++ b/samcli/local/init/templates/cookiecutter-aws-sam-hello-powershell/{{cookiecutter.project_name}}/README.md @@ -0,0 +1,146 @@ +# {{ cookiecutter.project_name }} + +This is a sample template for {{ cookiecutter.project_name }} + + +## Requirements + +* AWS CLI already configured with Administrator permission +* [Docker installed](https://www.docker.com/community-edition) +* [SAM CLI installed](https://github.com/awslabs/aws-sam-cli) +* [.NET Core installed](https://www.microsoft.com/net/download) +* [PowerShell Core installed](https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-powershell?view=powershell-6) +* [AWSLambdaPSCore PowerShell module](https://www.powershellgallery.com/packages/AWSLambdaPSCore/1.1.0.0) +* [Pester PowerShell module](https://github.com/pester/Pester) + +## Setup process + +### PowerShell (all Operating Systems) + +```powershell +build.ps1 +``` + +### Local development + +**Invoking function locally using a local sample payload** + +```bash +sam local invoke HelloWorldFunction --event event.json +``` + +**Invoking function locally through local API Gateway** + +```bash +sam local start-api +``` + +**SAM Local** is used to emulate both Lambda and API Gateway locally and uses our `template.yaml` to understand how to bootstrap this environment (runtime, where the source code is, etc.) - The following excerpt is what the CLI will read in order to initialize an API and its routes: + +```yaml +... +Events: + HelloWorldFunction: + Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api + Properties: + Path: /hello + Method: get +``` + +If the previous command run successfully you should now be able to hit the following local endpoint to invoke your function `http://localhost:3000/hello` + +## Packaging and deployment + +AWS Lambda PowerShell functions are compiled in to a .net core project before they are uploaded. Depencies are detected through the `#Requires` statement in your script file. After your project is built SAM will use `CodeUri` property to know where to look for the built application (including its dependencies): + +```yaml +... + HelloWorldFunction: + Type: AWS::Serverless::Function + Properties: + CodeUri: artifacts/HelloWorld.zip + ... +``` + +First and foremost, we need an `S3 bucket` where we can upload our Lambda functions packaged as ZIP before we deploy anything - If you don't have a S3 bucket to store code artifacts then this is a good time to create one: + +```bash +aws s3 mb s3://BUCKET_NAME +``` + +Next, run the following command to package our Lambda function to S3: + +```bash +sam package \ + --template-file template.yaml \ + --output-template-file packaged.yaml \ + --s3-bucket REPLACE_THIS_WITH_YOUR_S3_BUCKET_NAME +``` + +Next, the following command will create a Cloudformation Stack and deploy your SAM resources. + +```bash +sam deploy \ + --template-file packaged.yaml \ + --stack-name {{ cookiecutter.project_name.lower().replace(' ', '-') }} \ + --capabilities CAPABILITY_IAM +``` + +> **See [Serverless Application Model (SAM) HOWTO Guide](https://github.com/awslabs/serverless-application-model/blob/master/HOWTO.md) for more details in how to get started.** + +After deployment is complete you can run the following command to retrieve the API Gateway Endpoint URL: + +```bash +aws cloudformation describe-stacks \ + --stack-name {{ cookiecutter.project_name.lower().replace(' ', '-') }} \ + --query 'Stacks[].Outputs[?OutputKey==`HelloWorldApi`]' \ + --output table +``` + +## Testing + +### Powershell (all Operating Systems) + +```powershell +Invoke-Pester '[path to test directory]' +``` + +This will run all files that end in `tests.ps1` in that directory. + +# Appendix + +## SAM and AWS CLI commands + +All commands used throughout this document + +```bash +# Invoke function locally with event.json as an input +sam local invoke HelloWorldFunction --event event.json + +# Run API Gateway locally +sam local start-api + +# Create S3 bucket +aws s3 mb s3://BUCKET_NAME + +# Package Lambda function defined locally and upload to S3 as an artifact +sam package \ + --template-file template.yaml \ + --output-template-file packaged.yaml \ + --s3-bucket REPLACE_THIS_WITH_YOUR_S3_BUCKET_NAME + +# Deploy SAM template as a CloudFormation stack +sam deploy \ + --template-file packaged.yaml \ + --stack-name {{ cookiecutter.project_name.lower().replace(' ', '-') }} \ + --capabilities CAPABILITY_IAM + +# Describe Output section of CloudFormation stack previously created +aws cloudformation describe-stacks \ + --stack-name {{ cookiecutter.project_name.lower().replace(' ', '-') }} \ + --query 'Stacks[].Outputs[?OutputKey==`HelloWorldApi`]' \ + --output table + +# Tail Lambda function Logs using Logical name defined in SAM Template +sam logs -n HelloWorldFunction --stack-name {{ cookiecutter.project_name.lower().replace(' ', '-') }} --tail +``` diff --git a/samcli/local/init/templates/cookiecutter-aws-sam-hello-powershell/{{cookiecutter.project_name}}/src/Function.ps1 b/samcli/local/init/templates/cookiecutter-aws-sam-hello-powershell/{{cookiecutter.project_name}}/src/Function.ps1 new file mode 100644 index 0000000000..68d15b276b --- /dev/null +++ b/samcli/local/init/templates/cookiecutter-aws-sam-hello-powershell/{{cookiecutter.project_name}}/src/Function.ps1 @@ -0,0 +1,21 @@ +# PowerShell script file to be executed as a AWS Lambda function. +# +# When executing in Lambda the following variables will be predefined. +# $LambdaInput - A PSObject that contains the Lambda function input data. +# $LambdaContext - An Amazon.Lambda.Core.ILambdaContext object that contains information about the currently running Lambda environment. +# +# The last item in the PowerShell pipeline will be returned as the result of the Lambda function. +# +# To include PowerShell modules with your Lambda function, like the AWSPowerShell.NetCore module, add a "#Requires" statement +# indicating the module and version. + +#Requires -Modules @{ModuleName='AWSPowerShell.NetCore';ModuleVersion='3.3.221.0'} + +# This line publishes the input to CloudWatch logs so you know what triggered the function +Write-Host (ConvertTo-Json -InputObject $LambdaInput -Compress -Depth 5) + +return @{ + "message" = "hello world" +} + +# Your logic goes here diff --git a/samcli/local/init/templates/cookiecutter-aws-sam-hello-powershell/{{cookiecutter.project_name}}/src/build.ps1 b/samcli/local/init/templates/cookiecutter-aws-sam-hello-powershell/{{cookiecutter.project_name}}/src/build.ps1 new file mode 100644 index 0000000000..0760036ee5 --- /dev/null +++ b/samcli/local/init/templates/cookiecutter-aws-sam-hello-powershell/{{cookiecutter.project_name}}/src/build.ps1 @@ -0,0 +1,4 @@ +Import-Module -Name AWSLambdaPSCore + +$scriptPath = Join-Path -Path $PSScriptRoot -ChildPath "Function.ps1" +New-AWSPowerShellLambdaPackage -ScriptPath $scriptPath -OutputPackage "{{ cookiecutter.project_name }}/artifacts/Function.zip" diff --git a/samcli/local/init/templates/cookiecutter-aws-sam-hello-powershell/{{cookiecutter.project_name}}/template.yaml b/samcli/local/init/templates/cookiecutter-aws-sam-hello-powershell/{{cookiecutter.project_name}}/template.yaml new file mode 100644 index 0000000000..48a3bf6dcc --- /dev/null +++ b/samcli/local/init/templates/cookiecutter-aws-sam-hello-powershell/{{cookiecutter.project_name}}/template.yaml @@ -0,0 +1,33 @@ +AWSTemplateFormatVersion: '2010-09-09' +Transform: AWS::Serverless-2016-10-31 +Description: > + Sample SAM Template for {{ cookiecutter.project_name }} + +# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst +Globals: + Function: + Timeout: 60 + + +Resources: + + PowerShellFunction: + Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction + Properties: + CodeUri: ./artifacts/Function.zip + Handler: Function::Function.Bootstrap::ExecuteFunction + Runtime: dotnetcore2.1 + MemorySize: 512 + Environment: # More info about Env Vars: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#environment-object + Variables: + PARAM1: VALUE + +Outputs: + + HelloWorldFunction: + Description: "PowerShell Lambda Function ARN" + Value: !GetAtt HelloWorldFunction.Arn + + HelloWorldFunctionIamRole: + Description: "Implicit IAM Role created for Hello World function" + Value: !GetAtt HelloWorldFunctionRole.Arn diff --git a/samcli/local/init/templates/cookiecutter-aws-sam-hello-powershell/{{cookiecutter.project_name}}/test/Function.tests.ps1 b/samcli/local/init/templates/cookiecutter-aws-sam-hello-powershell/{{cookiecutter.project_name}}/test/Function.tests.ps1 new file mode 100644 index 0000000000..bfeff07391 --- /dev/null +++ b/samcli/local/init/templates/cookiecutter-aws-sam-hello-powershell/{{cookiecutter.project_name}}/test/Function.tests.ps1 @@ -0,0 +1,15 @@ +Import-Module -Name Pester + +Describe "HelloWorld Tests" { + + $srcRoot = Join-Path -Path $PSScriptRoot -ChildPath "../src" -Resolve + + Mock -CommandName "Write-Host" -MockWith {} + + It "Should write the input to the host stream" { + $functionPath = Join-Path -Path $srcRoot -ChildPath "Function.ps1" + $result = . $functionPath + Assert-MockCalled -CommandName Write-Host -Times 1 + $result.message | Should Be "hello world" + } +}