By using AWS re:Post, you agree to the Terms of Use
/Serverless/

Serverless

Serverless is a way to describe the services, practices, and strategies that enable you to build more agile applications so you can innovate and respond to change faster. With serverless computing, infrastructure management tasks like capacity provisioning and patching are handled by AWS, so you can focus on only writing code that serves your customers.

Recent questions

see all
1/18

Cognito - CustomSMSSender InvalidCiphertextException: null on Code Decrypt (Golang)

Hi, i followed this document to customize cognito SMS delivery flow https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-custom-sms-sender.html I'm not working on a Javascript environment so wrote this Go snippet: ``` package main import ( "context" golog "log" "os" "github.com/aws/aws-lambda-go/events" "github.com/aws/aws-lambda-go/lambda" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/kms" ) // USING THIS TYPES BECAUSE AWS-SDK-GO DOES NOT SUPPORTS THIS // CognitoEventUserPoolsCustomSmsSender is sent by AWS Cognito User Pools before each mail to send. type CognitoEventUserPoolsCustomSmsSender struct { events.CognitoEventUserPoolsHeader Request CognitoEventUserPoolsCustomSmsSenderRequest `json:"request"` } // CognitoEventUserPoolsCustomSmsSenderRequest contains the request portion of a CustomSmsSender event type CognitoEventUserPoolsCustomSmsSenderRequest struct { UserAttributes map[string]interface{} `json:"userAttributes"` Code string `json:"code"` ClientMetadata map[string]string `json:"clientMetadata"` Type string `json:"type"` } func main() { lambda.Start(sendCustomSms) } func sendCustomSms(ctx context.Context, event *CognitoEventUserPoolsCustomSmsSender) error { golog.Printf("received event=%+v", event) golog.Printf("received ctx=%+v", ctx) config := aws.NewConfig().WithRegion(os.Getenv("AWS_REGION")) session, err := session.NewSession(config) if err != nil { return err } kmsProvider := kms.New(session) smsCode, err := kmsProvider.Decrypt(&kms.DecryptInput{ KeyId: aws.String("a8a566c5-796a-4ba1-8715-c9c17c6f0cb5"), CiphertextBlob: []byte(event.Request.Code), }) if err != nil { return err } golog.Printf("decrypted code %v", smsCode.Plaintext) return nil } ``` i'm always getting `InvalidCiphertextException: : InvalidCiphertextException null`, can someone help? This is how lambda config looks on my user pool: ``` "LambdaConfig": { "CustomSMSSender": { "LambdaVersion": "V1_0", "LambdaArn": "arn:aws:lambda:eu-west-1:...:function:cognito-custom-auth-sms-sender-dev" }, "KMSKeyID": "arn:aws:kms:eu-west-1:...:key/a8a566c5-796a-4ba1-8715-c9c17c6f0cb5" }, ```
0
answers
0
votes
0
views
AWS-User-1153293
asked a day ago

Annoying HLS Playback Problem On Windows But Not iOS

Hello All, I am getting up to speed with CloudFront and S3 for VOD. I have used the CloudFormation template. Uploaded an MP4, obtained the Key for the m3u8 file. I create a distribution in CF. I embed it in my webpage. For the most part, it works great. But there is a significantly long buffering event during the first few seconds. This problem does not exist when I play the video on my iOS device. And strangely, it does not happen when I play it in Akami's HLS tester on my Windows 11 PC using Chrome. The problem seems to only occur when I play it from my website, using any browser, on my Windows 11 PC. Steps I take to provoke the issue: Open an Incognito tab in Chrome / navigate to my website, my player is set to auto play so it auto plays / the video starts out a bit fuzzy, it then stops for a second / restarts with great resolution / and stays that way until the endo f the video. If I play again, no problems at all, but that is to be expected. I assume there is a local cache. Steps I have tried to fix / clues: I have tried different segment lengths via modifying the Lambda function created when the stack was formed by the template. The default was 5. At that setting, the fuzzy aspect lasted the longest but the buffer event seemed slightly shorter. At 1 and 2, the fuzzy is far shorter but the buffering event is notably longer. One thought, could this be related to the video player I am using? I wanted to use the AWS IVS but could not get it working the first go around so I tried the amazon-ivs-videojs. That worked immediately, except for the buffer issue. And as the buffer issue seems to go away when I test the distribution via the Akami HLS tester. As always, much appreciation for reading this question and any time spent pondering on it.
0
answers
0
votes
4
views
Redbone
asked 2 days ago

Lambda Execution Function Issue For RDS Reboot

Greetings, I created a simple function taking as reference the basic Lambda in Python to start/stop RDS from here: [https://aws.amazon.com/es/blogs/database/schedule-amazon-rds-stop-and-start-using-aws-lambda/]() But I changed it for reboot purposes, so my Python code is the following: ``` # Lambda for RDS reboot given a REGION, KEY and VALUE import boto3 import os import sys import time from datetime import datetime, timezone from time import gmtime, strftime # REGION: the rds region # KEY - VALUE: the KEY and VALUE from RDS tag def reboot_rds(): region = os.environ["REGION"] key = os.environ["KEY"] value = os.environ["VALUE"] client = boto3.client("rds", region_name=region) response = client.describe_db_instances() v_readReplica = [] for i in response["DBInstances"]: readReplica = i["ReadReplicaDBInstanceIdentifiers"] v_readReplica.extend(readReplica) for i in response["DBInstances"]: # Check if the RDS is Aurora if i["Engine"] not in ["aurora-mysql", "aurora-postgresql"]: # Check if RDS is a replica instance if ( i["DBInstanceIdentifier"] not in v_readReplica and len(i["ReadReplicaDBInstanceIdentifiers"]) == 0 ): arn = i["DBInstanceArn"] resp2 = client.list_tags_for_resource(ResourceName=arn) # Check tag if 0 == len(resp2["TagList"]): print("Instance {0} tag value is not correct".format(i["DBInstanceIdentifier"])) else: for tag in resp2["TagList"]: # if tag values match if tag["Key"] == key and tag["Value"] == value: if i["DBInstanceStatus"] == "available": client.reboot_db_instance( DBInstanceIdentifier=i["DBInstanceIdentifier"], ForceFailover=False, ) print("Rebooting RDS {0}".format(i["DBInstanceIdentifier"])) elif i["DBInstanceStatus"] == "rebooting": print( "Instance RDS {0} is already rebooting".format( i["DBInstanceIdentifier"] ) ) elif i["DBInstanceStatus"] == "creating": print( "Instance RDS {0} is on creation, try later".format( i["DBInstanceIdentifier"] ) ) elif i["DBInstanceStatus"] == "modifying": print( "Instance RDS {0} {0} is modifying, try later".format( i["DBInstanceIdentifier"] ) ) elif i["DBInstanceStatus"] == "stopped": print( "Cannot reboot RDS {0} it is already stopped".format( i["DBInstanceIdentifier"] ) ) elif i["DBInstanceStatus"] == "starting": print( "Instance RDS {0} is starting, try later".format( i["DBInstanceIdentifier"] ) ) elif i["DBInstanceStatus"] == "stopping": print( "Instance RDS {0} is stopping, try later.".format( i["DBInstanceIdentifier"] ) ) elif tag["Key"] != key and tag["Value"] != value: print( "Tag values {0} doesn't match".format(i["DBInstanceIdentifier"]) ) elif len(tag["Key"]) == 0 or len(tag["Value"]) == 0: print("Error {0}".format(i["DBInstanceIdentifier"])) else: print( "Instance RDS {0} is on a different state, check the RDS monitor for more info".format( i["DBInstanceIdentifier"] ) ) def lambda_handler(event, context): reboot_rds() ``` My environment variables: | Key| Value | | --- | --- | | KEY | tmptest | | REGION | us-east-1e | | VALUE| reboot| And finally my event named 'Test' `{ "key1": "tmptest", "key2": "us-east-1e", "key3": "reboot" }` I checked the indentation of my code before execute it and its fine, but in execution of my test event I got the following output: `{ "errorMessage": "2022-01-14T14:50:22.245Z b8d0dc59-714d-4543-8651-b5a2532dfe8e Task timed out after 1.00 seconds" }` ``` START RequestId: b8d0dc59-714d-4543-8651-b5a2532dfe8e Version: $LATEST END RequestId: b8d0dc59-714d-4543-8651-b5a2532dfe8e REPORT RequestId: b8d0dc59-714d-4543-8651-b5a2532dfe8e Duration: 1000.76 ms Billed Duration: 1000 ms Memory Size: 128 MB Max Memory Used: 65 MB Init Duration: 243.69 ms 2022-01-14T14:50:22.245Z b8d0dc59-714d-4543-8651-b5a2532dfe8e Task timed out after 1.00 seconds ``` Also my test RDS has the correct tag values in order to get the reboot action but nothing, until now I cannot reboot my instance with my Lambda function. Any clue what's wrong with my code? Maybe some additional configuration issue or something in my code is not correct, I don't know. I'd appreciate if someone can give a hand with this. **UPDATE 2022/01/15** As suggestion of **Brettski@AWS** I increased the time from 1 second to 10 then I got the following error message: ``` { "errorMessage": "Could not connect to the endpoint URL: \"https://rds.us-east-1e.amazonaws.com/\"", "errorType": "EndpointConnectionError", "requestId": "b2bb3840-42a2-4220-84b4-642d17d7a9e6", "stackTrace": [ " File \"/var/task/lambda_function.py\", line 103, in lambda_handler\n reiniciar_rds()\n", " File \"/var/task/lambda_function.py\", line 16, in reiniciar_rds\n response = client.describe_db_instances()\n", " File \"/var/runtime/botocore/client.py\", line 386, in _api_call\n return self._make_api_call(operation_name, kwargs)\n", " File \"/var/runtime/botocore/client.py\", line 691, in _make_api_call\n http, parsed_response = self._make_request(\n", " File \"/var/runtime/botocore/client.py\", line 711, in _make_request\n return self._endpoint.make_request(operation_model, request_dict)\n", " File \"/var/runtime/botocore/endpoint.py\", line 102, in make_request\n return self._send_request(request_dict, operation_model)\n", " File \"/var/runtime/botocore/endpoint.py\", line 136, in _send_request\n while self._needs_retry(attempts, operation_model, request_dict,\n", " File \"/var/runtime/botocore/endpoint.py\", line 253, in _needs_retry\n responses = self._event_emitter.emit(\n", " File \"/var/runtime/botocore/hooks.py\", line 357, in emit\n return self._emitter.emit(aliased_event_name, **kwargs)\n", " File \"/var/runtime/botocore/hooks.py\", line 228, in emit\n return self._emit(event_name, kwargs)\n", " File \"/var/runtime/botocore/hooks.py\", line 211, in _emit\n response = handler(**kwargs)\n", " File \"/var/runtime/botocore/retryhandler.py\", line 183, in __call__\n if self._checker(attempts, response, caught_exception):\n", " File \"/var/runtime/botocore/retryhandler.py\", line 250, in __call__\n should_retry = self._should_retry(attempt_number, response,\n", " File \"/var/runtime/botocore/retryhandler.py\", line 277, in _should_retry\n return self._checker(attempt_number, response, caught_exception)\n", " File \"/var/runtime/botocore/retryhandler.py\", line 316, in __call__\n checker_response = checker(attempt_number, response,\n", " File \"/var/runtime/botocore/retryhandler.py\", line 222, in __call__\n return self._check_caught_exception(\n", " File \"/var/runtime/botocore/retryhandler.py\", line 359, in _check_caught_exception\n raise caught_exception\n", " File \"/var/runtime/botocore/endpoint.py\", line 200, in _do_get_response\n http_response = self._send(request)\n", " File \"/var/runtime/botocore/endpoint.py\", line 269, in _send\n return self.http_session.send(request)\n", " File \"/var/runtime/botocore/httpsession.py\", line 373, in send\n raise EndpointConnectionError(endpoint_url=request.url, error=e)\n" ] } ``` It's strange because my VPC configuration is fine, it's the same VPC of my RDS, its zone and the same security group. What else have I to consider in order to make my code work properly?
2
answers
0
votes
5
views
TEENEESE
asked 2 days ago

aws lambda - ES6 module error : module is not defined in ES module scope

Based on these resources : https://aws.amazon.com/about-aws/whats-new/2022/01/aws-lambda-es-modules-top-level-await-node-js-14/ https://aws.amazon.com/blogs/compute/using-node-js-es-modules-and-top-level-await-in-aws-lambda/ it is clear that aws nodejs 14.x now supports ES6 module. However, when I to run a nodejs app with ES6 module, I get this error ``` undefined ERROR Uncaught Exception { "errorType": "ReferenceError", "errorMessage": "module is not defined in ES module scope\nThis file is being treated as an ES module because it has a '.js' file extension and '/var/task/package.json' contains \"type\": \"module\". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.", "stack": [ "ReferenceError: module is not defined in ES module scope", "This file is being treated as an ES module because it has a '.js' file extension and '/var/task/package.json' contains \"type\": \"module\". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.", " at file:///var/task/index.js:20:1", " at ModuleJob.run (internal/modules/esm/module_job.js:183:25)", " at process.runNextTicks [as _tickCallback] (internal/process/task_queues.js:60:5)", " at /var/runtime/deasync.js:23:15", " at _tryAwaitImport (/var/runtime/UserFunction.js:74:12)", " at _tryRequire (/var/runtime/UserFunction.js:162:21)", " at _loadUserApp (/var/runtime/UserFunction.js:197:12)", " at Object.module.exports.load (/var/runtime/UserFunction.js:242:17)", " at Object.<anonymous> (/var/runtime/index.js:43:30)", " at Module._compile (internal/modules/cjs/loader.js:1085:14)" ] } ``` I have already added `"type": "module" `in package.json package.json ``` { "name": "autoprocess", "version": "1.0.0", "description": "", "main": "index.js", "type": "module", "scripts": { }, "author": "", "license": "ISC", "dependencies": { "@aws-sdk/client-sqs": "^3.41.0", "aws-sdk": "^2.1030.0", "check-if-word": "^1.2.1", "express": "^4.17.1", "franc": "^6.0.0", "is-html": "^3.0.0", "nodemon": "^2.0.15" } } ``` index.json ``` 'use strict'; import StringMessage from './StringMessage.js'; module.exports.handler = async (event) => { var data = JSON.parse(event.body); //other code goes here let response = { statusCode: 200, headers: { }, body: "" }; console.log("response: " + JSON.stringify(response)) return response; }; ``` I have also tried replacing "module.exports.handler" with "exports.handler ". this does not work either. error message shows "exports is not defined in ES module scope" What am I doing wrong? additional info: I am uploading the function code via zip file
1
answers
0
votes
4
views
az-gi
asked 3 days ago

aws-sdk V3 timeout in lambda

Hello, I'm using NodeJS 14.x lambda to control an ecs service. As I do not need the ecs task to run permanently, I created a service inside the cluster so I can play around the desired count to start or stop it at will. I also created two lambdas, one for querying the current desired count and the current Public IP, another one for updating said desired count (to 0 or 1 should I want to start or stop it) I have packed aws-sdk v3 on a lambda layer to not have to package it on each lambda. Seems to work fine as I was getting runtime error > "Runtime.ImportModuleError: Error: Cannot find module '@aws-sdk/client-ecs'" But I do not anymore. The code is also working fine from my workstation as I'm able to execute it locally and I get the desired result (query to ecs api works fine) But All I get when testing from lambdas are Timeouts... It usually execute in less than 3 secondes on my local workstation but even with a lambda timeout set up at 3 minutes, this is what I get ``` START RequestId: XXXX-XX-XXXX Version: $LATEST 2022-01-11T23:57:59.528Z XXXX-XX-XXXX INFO before ecs client send END RequestId: XXXX-XX-XXXX REPORT RequestId: XXXX-XX-XXXX Duration: 195100.70 ms Billed Duration: 195000 ms Memory Size: 128 MB Max Memory Used: 126 MB Init Duration: 1051.68 ms 2022-01-12T00:01:14.533Z XXXX-XX-XXXX Task timed out after 195.10 seconds ``` The message `before ecs client send` is a console.log I made just before the ecs.send request for debug purposes I think I've set up the policy correctly, as well as the Lambda VPC with the default outbound rule to allow all protocol on all port to 0.0.0.0/0 so I I have no idea on where to look now. I have not found any way to debug aws-sdk V3 calls like you would do on V2 by adding a logger to the config. Maybe it could help understanding the issue....
1
answers
0
votes
5
views
Tomazed
asked 5 days ago

Popular users

see all
1/18

Learn AWS faster by following popular topics

1/5