AWS Tools for Windows PowerShell
Command Reference

AWS services or capabilities described in AWS Documentation may vary by region/location. Click Getting Started with Amazon AWS to see specific differences applicable to the China (Beijing) Region.

Synopsis

Calls the AWS Lambda CreateFunction API operation.

Syntax

FromMemoryStream (Default)

Publish-LMFunction
-FunctionName <String>
-Code_ZipFile <Byte[]>
-Handler <String>
-Runtime <Runtime>
-Role <String>
-Publish <SwitchParameter>
-Description <String>
-Environment_IsVariablesSet <Boolean>
-KMSKeyArn <String>
-Layer <String[]>
-MemorySize <Int32>
-TracingConfig_Mode <TracingMode>
-PublishVersion <Boolean>
-VpcConfig_SecurityGroupId <String[]>
-VpcConfig_SubnetId <String[]>
-Tag <Hashtable>
-DeadLetterConfig_TargetArn <String>
-Timeout <Int32>
-Environment_Variable <Hashtable>
-Select <String>
-PassThru <SwitchParameter>
-Force <SwitchParameter>

FromZipFile

Publish-LMFunction
-FunctionName <String>
-ZipFilename <String>
-Handler <String>
-Runtime <Runtime>
-Role <String>
-Publish <SwitchParameter>
-Description <String>
-Environment_IsVariablesSet <Boolean>
-KMSKeyArn <String>
-Layer <String[]>
-MemorySize <Int32>
-TracingConfig_Mode <TracingMode>
-PublishVersion <Boolean>
-VpcConfig_SecurityGroupId <String[]>
-VpcConfig_SubnetId <String[]>
-Tag <Hashtable>
-DeadLetterConfig_TargetArn <String>
-Timeout <Int32>
-Environment_Variable <Hashtable>
-Select <String>
-PassThru <SwitchParameter>
-Force <SwitchParameter>

FromS3Object

Publish-LMFunction
-FunctionName <String>
-Handler <String>
-Runtime <Runtime>
-Role <String>
-Publish <SwitchParameter>
-Description <String>
-Environment_IsVariablesSet <Boolean>
-KMSKeyArn <String>
-Layer <String[]>
-MemorySize <Int32>
-TracingConfig_Mode <TracingMode>
-PublishVersion <Boolean>
-Code_S3Bucket <String>
-Code_S3Key <String>
-Code_S3ObjectVersion <String>
-VpcConfig_SecurityGroupId <String[]>
-VpcConfig_SubnetId <String[]>
-Tag <Hashtable>
-DeadLetterConfig_TargetArn <String>
-Timeout <Int32>
-Environment_Variable <Hashtable>
-Select <String>
-PassThru <SwitchParameter>
-Force <SwitchParameter>

Description

Creates a Lambda function. To create a function, you need a deployment package and an execution role. The deployment package contains your function code. The execution role grants the function permission to use AWS services, such as Amazon CloudWatch Logs for log streaming and AWS X-Ray for request tracing. When you create a function, Lambda provisions an instance of the function and its supporting resources. If your function connects to a VPC, this process can take a minute or so. During this time, you can't invoke or modify the function. The State, StateReason, and StateReasonCode fields in the response from GetFunctionConfiguration indicate when the function is ready to invoke. For more information, see Function States. A function has an unpublished version, and can have published versions and aliases. The unpublished version changes when you update your function's code and configuration. A published version is a snapshot of your function code and configuration that can't be changed. An alias is a named resource that maps to a version, and can be changed to map to a different version. Use the Publish parameter to create version 1 of your function from its initial configuration. The other parameters let you configure version-specific and function-level settings. You can modify version-specific settings later with UpdateFunctionConfiguration. Function-level settings apply to both the unpublished and published versions of the function, and include tags (TagResource) and per-function concurrency limits (PutFunctionConcurrency). If another account or an AWS service invokes your function, use AddPermission to grant permission by creating a resource-based IAM policy. You can grant permissions at the function level, on a version, or on an alias. To invoke your function directly, use Invoke. To invoke your function in response to events in other AWS services, create an event source mapping (CreateEventSourceMapping), or configure a function trigger in the other service. For more information, see Invoking Functions.

Parameters

-Code_S3Bucket <String>
An Amazon S3 bucket in the same AWS Region as your function. The bucket can be in a different AWS account.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesBucketName, FunctionCode_S3Bucket, S3Bucket
-Code_S3Key <String>
The Amazon S3 key of the deployment package.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesFunctionCode_S3Key, Key, S3Key
-Code_S3ObjectVersion <String>
For versioned objects, the version of the deployment package object to use.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesFunctionCode_S3ObjectVersion, S3ObjectVersion, VersionId
-Code_ZipFile <Byte[]>
The base64-encoded contents of the deployment package. AWS SDK and AWS CLI clients handle the encoding for you.The cmdlet will automatically convert the supplied parameter of type string, string[], System.IO.FileInfo or System.IO.Stream to byte[] before supplying it to the service.
Required?False
Position?2
Accept pipeline input?True (ByPropertyName)
AliasesZipContent, ZipFileContent
-DeadLetterConfig_TargetArn <String>
The Amazon Resource Name (ARN) of an Amazon SQS queue or Amazon SNS topic.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-Description <String>
A description of the function.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-Environment_IsVariablesSet <Boolean>
This property is set to true if the property is set; false otherwise. This property can be used to determine if the related property was returned by a service response or if the related property should be sent to the service during a service call.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-Environment_Variable <Hashtable>
Environment variable key-value pairs.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesEnvironment_Variables
This parameter overrides confirmation prompts to force the cmdlet to continue its operation. This parameter should always be used with caution.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-FunctionName <String>
Amazon.Lambda.Model.CreateFunctionRequest.FunctionName
Required?False
Position?1
Accept pipeline input?True (ByValue, ByPropertyName)
-Handler <String>
The name of the method within your code that Lambda calls to execute your function. The format includes the file name. It can also include namespaces and other qualifiers, depending on the runtime. For more information, see Programming Model.
Required?False
Position?3
Accept pipeline input?True (ByPropertyName)
-KMSKeyArn <String>
The ARN of the AWS Key Management Service (AWS KMS) key that's used to encrypt your function's environment variables. If it's not provided, AWS Lambda uses a default service key.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-Layer <String[]>
A list of function layers to add to the function's execution environment. Specify each layer by its ARN, including the version.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesLayers
-MemorySize <Int32>
The amount of memory that your function has access to. Increasing the function's memory also increases its CPU allocation. The default value is 128 MB. The value must be a multiple of 64 MB.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-PassThru <SwitchParameter>
Changes the cmdlet behavior to return the value passed to the FunctionName parameter. The -PassThru parameter is deprecated, use -Select '^FunctionName' instead. This parameter will be removed in a future version.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-Publish <SwitchParameter>
This parameter is obsolete. Use PublishVersion instead.
Required?False
Position?Named
Accept pipeline input?False
-PublishVersion <Boolean>
Set to true to publish the first version of the function during creation.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-Role <String>
The Amazon Resource Name (ARN) of the function's execution role.
Required?False
Position?5
Accept pipeline input?True (ByPropertyName)
-Runtime <Runtime>
The identifier of the function's runtime.
Required?True
Position?4
Accept pipeline input?True (ByPropertyName)
-Select <String>
Use the -Select parameter to control the cmdlet output. The default value is '*'. Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.Lambda.Model.CreateFunctionResponse). Specifying the name of a property of type Amazon.Lambda.Model.CreateFunctionResponse will result in that property being returned. Specifying -Select '^ParameterName' will result in the cmdlet returning the selected cmdlet parameter value.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-Tag <Hashtable>
A list of tags to apply to the function.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesTags
-Timeout <Int32>
The amount of time that Lambda allows a function to run before stopping it. The default is 3 seconds. The maximum allowed value is 900 seconds.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-TracingConfig_Mode <TracingMode>
The tracing mode.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-VpcConfig_SecurityGroupId <String[]>
A list of VPC security groups IDs.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesVpcConfig_SecurityGroupIds
-VpcConfig_SubnetId <String[]>
A list of VPC subnet IDs.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesVpcConfig_SubnetIds
-ZipFilename <String>
This parameter is obsolete and will be removed in a future version. Use 'Code_ZipFile' instead. The path to a zip file containing your deployment package. For more information about creating a .zip file, go to Execution Permissions in the AWS Lambda Developer Guide.
Required?True
Position?2
Accept pipeline input?True (ByPropertyName)
AliasesFunctionZip, Filename

Common Credential and Region Parameters

-AccessKey <String>
The AWS access key for the user account. This can be a temporary access key if the corresponding session token is supplied to the -SessionToken parameter.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesAK
-Credential <AWSCredentials>
An AWSCredentials object instance containing access and secret key information, and optionally a token for session-based credentials.
Required?False
Position?Named
Accept pipeline input?True (ByValue, ByPropertyName)
-EndpointUrl <String>
The endpoint to make the call against.Note: This parameter is primarily for internal AWS use and is not required/should not be specified for normal usage. The cmdlets normally determine which endpoint to call based on the region specified to the -Region parameter or set as default in the shell (via Set-DefaultAWSRegion). Only specify this parameter if you must direct the call to a specific custom endpoint.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-NetworkCredential <PSCredential>
Used with SAML-based authentication when ProfileName references a SAML role profile. Contains the network credentials to be supplied during authentication with the configured identity provider's endpoint. This parameter is not required if the user's default network identity can or should be used during authentication.
Required?False
Position?Named
Accept pipeline input?True (ByValue, ByPropertyName)
-ProfileLocation <String>
Used to specify the name and location of the ini-format credential file (shared with the AWS CLI and other AWS SDKs)If this optional parameter is omitted this cmdlet will search the encrypted credential file used by the AWS SDK for .NET and AWS Toolkit for Visual Studio first. If the profile is not found then the cmdlet will search in the ini-format credential file at the default location: (user's home directory)\.aws\credentials.If this parameter is specified then this cmdlet will only search the ini-format credential file at the location given.As the current folder can vary in a shell or during script execution it is advised that you use specify a fully qualified path instead of a relative path.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesAWSProfilesLocation, ProfilesLocation
-ProfileName <String>
The user-defined name of an AWS credentials or SAML-based role profile containing credential information. The profile is expected to be found in the secure credential file shared with the AWS SDK for .NET and AWS Toolkit for Visual Studio. You can also specify the name of a profile stored in the .ini-format credential file used with the AWS CLI and other AWS SDKs.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesStoredCredentials, AWSProfileName
-Region <Object>
The system name of an AWS region or an AWSRegion instance. This governs the endpoint that will be used when calling service operations. Note that the AWS resources referenced in a call are usually region-specific.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesRegionToCall
-SecretKey <String>
The AWS secret key for the user account. This can be a temporary secret key if the corresponding session token is supplied to the -SessionToken parameter.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesSK, SecretAccessKey
-SessionToken <String>
The session token if the access and secret keys are temporary session-based credentials.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesST

Outputs

This cmdlet returns an Amazon.Lambda.Model.CreateFunctionResponse object containing multiple properties. The object can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack.

Examples

Example 1

PS C:\> Publish-LMFunction -Description "My C# Lambda Function" `
-FunctionName MyFunction `
-ZipFilename .\MyFunctionBinaries.zip `
-Handler "AssemblyName::Namespace.ClassName::MethodName" `
-Role "arn:aws:iam::123456789012:role/LambdaFullExecRole" `
-Runtime dotnetcore1.0 `
-Environment_Variable @{ "envvar1"="value";"envvar2"="value" }

CodeSha256 : /NgBMd...gq71I=
CodeSize : 214784
DeadLetterConfig :
Description : My C# Lambda Function
Environment : Amazon.Lambda.Model.EnvironmentResponse
FunctionArn : arn:aws:lambda:us-west-2:123456789012:function:ToUpper
FunctionName : MyFunction
Handler : AssemblyName::Namespace.ClassName::MethodName
KMSKeyArn :
LastModified : 2016-12-29T23:50:14.207+0000
MemorySize : 128
Role : arn:aws:iam::123456789012:role/LambdaFullExecRole
Runtime : dotnetcore1.0
Timeout : 3
Version : $LATEST
VpcConfig :
This example creates a new C# (dotnetcore1.0 runtime) function named MyFunction in AWS Lambda, providing the compiled binaries for the function from a zip file on the local file system (relative or absolute paths may be used). C# Lambda functions specify the handler for the function using the designation AssemblyName::Namespace.ClassName::MethodName. You should replace the assembly name (without .dll suffix), namespace, class name and method name parts of the handler spec appropriately. The new function will have environment variables 'envvar1' and 'envvar2' set up from the provided values.

Example 2

PS C:\> Write-S3Object -BucketName mybucket -Key MyFunctionBinaries.zip -File .\MyFunctionBinaries.zip
PS C:\> Publish-LMFunction -Description "My C# Lambda Function" `
-FunctionName MyFunction `
-BucketName mybucket `
-Key MyFunctionBinaries.zip `
-Handler "AssemblyName::Namespace.ClassName::MethodName" `
-Role "arn:aws:iam::123456789012:role/LambdaFullExecRole" `
-Runtime dotnetcore1.0 `
-Environment_Variable @{ "envvar1"="value";"envvar2"="value" }
This example is similar to the previous one except the function binaries are first uploaded to an Amazon S3 bucket (which must be in the same region as the intended Lambda function) and the resulting S3 object is then referenced when creating the function.

Supported Version

AWS Tools for PowerShell: 2.x.y.z