- Newest
- Most votes
- Most comments
This should be working without any issues, if configured correctly.
You could leverage the AWS Lambda Developer Guide - there is an example of setting up a basic infrastructure for a PowerShell Lambda (the link above points directly to that example).
Following the steps in the guide, you get an AWS Lambda with the .NET Core 3.1 (C#/PowerShell) runtime and some basic CmdLets as an example.
To test your use case, I manually created a simple secret in the AWS Secrets Manager with a secret ID test-secret
. I used the DefaultEncryptionKey
and no additional options. I placed the secret in the same region where my Lambda function resides (eu-west-1
in my case).
In the Lambda function, I call the AWS API as follows:
$secret = Get-SECSecretValue -SecretId test-secret Write-Host $secret.SecretString
To allow AWS Lambda to access my newly created secret, I extended the already pre-configured Lambda execution role with an inline policy (here, I anonymized some values with *
):
{ "Version": "2012-10-17", "Statement": [ { "Sid": "MySecretAccess", "Effect": "Allow", "Action": "secretsmanager:GetSecretValue", "Resource": "arn:aws:secretsmanager:eu-west-1:************:secret:test-secret-******" } ] }
So this immediately worked out-of-the-box, here is my CloudWatch log for this function call:
Importing module ./Modules/AWSPowerShell.NetCore/3.3.618.0/AWSPowerShell.NetCore.psd1 [Information] - {"test-secret":"TEST_SECRET_VALUE"}
Please try the steps from the guide I mentioned above and see if this works for you. If it still doesn't, I'm happy to help, but please take a look on your CloudWatch logs and also make sure your deployment works.
Relevant content
- asked 3 years ago
- asked a year ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 3 years ago
- AWS OFFICIALUpdated 5 months ago
- AWS OFFICIALUpdated 2 years ago
Following the Developer Guide, I created a basic lambda and modified the code as such: #Requires -Modules @{ModuleName='AWS.Tools.SecretsManager';ModuleVersion='4.1.24.0'} write-host(Get-SECSecretValue -SecretId "TestKeys" -verbose)
Execution role has been extended with "Effect": "Allow", "Action": "secretsmanager:", "Resource": "arn:aws:secretsmanager:us-east-1:*****************:secret:TestKeys-*********"
Cloudwatch log: 2022-02-22T13:39:29.043-06:00 START RequestId: {task guid} Version: $LATEST
2022-02-22T13:39:29.047-06:00 Importing module ./Modules/AWS.Tools.Common/4.1.24.0/AWS.Tools.Common.psd1 Importing module ./Modules/AWS.Tools.SecretsManager/4.1.24.0/AWS.Tools.SecretsManager.psd1
2022-02-22T13:39:29.964-06:00 [Verbose] - Invoking AWS Secrets Manager operation 'GetSecretValue' in region 'us-east-1'
2022-02-22T13:39:59.077-06:00 END RequestId: {task guid}
2022-02-22T13:39:59.077-06:00 REPORT RequestId: {task guid} Duration: 30030.73 ms Billed Duration: 30000 ms Memory Size: 512 MB Max Memory Used: 161 MB Init Duration: 2328.03 ms
2022-02-22T13:39:59.077-06:00 2022-02-22T19:39:59.075Z {task guid} Task timed out after 30.03 seconds
I had been following the documentation here: https://docs.aws.amazon.com/lambda/latest/dg/powershell-devenv.html In changing from the module import "AWS.Tools.Common" to the older "AWSPowerShell.NetCore" I now get an SSL error "The remote certificate is invalid according to the validation procedure." How am I getting SSL cert errors when I'm not even using external services? I am initiating the lambda via the Test function, and I have used the CLI to invoke it with the same results.