Questions tagged with AWS Lambda

Content language: English

Sort by most recent

Browse through the questions and answers listed below or filter and sort to narrow down your results.

Updating an ECS service automatically using the CLI via Lambda

I have a multi-container application that runs a service on ECS. The images are hosted on ECR, configuration files are pulled from a S3 bucket during container startup via script. The application sits behind a network loadbalancer with EIP. The loadbalancer is in a public subnet and reachable, the app itself is inside a private subnet. My ultimate goal is to automatically update the service when either a.) a new image is checked in or b.) a new configuration file is uploaded. I figured the best way to do this behind a network load balancer (which supports rolling update) is to use the AWS ECS CLi inside a lambda function that triggers upon update. If I did not misread the docs, the CLI should trigger a rolling update. To test the CLI, I tried: `aws ecs update-service --cluster mycluster --service myservice --force-new-deployment` However, this was not successful. A new task was created, but was stopped before deployment was finished with log message: > Essential container in task exited Parameters for the service are min. 100 % and max. 200 %. I also tried to set the lower bound of running tasks to 0 %. This resulted in the successful exit of the old task, but the new tasks failed to deploy with the same error. This makes me think that I probably configured something incorrectly. Questions: 1.) Is using a lambda function a smart choice here? Or is there a better way? 2.) How can I troubleshoot the failing rolling update? I appreciate any help! If you need more information, please let me know. Best regards, Sebastian
1
answers
0
votes
20
views
asked 9 days ago

Concurrent executions of Lambda functions

I would like to understand how many calls of a Lambda function, through AWS-SDK, I can perform simultaneously. Now I am a free tier and it seems that I can't performe more than 10 concurrently executions. In my project, each client is going to make running a function and so the number of concurrently executions that my aws account can performe would be equal to the number of clients that my web app can serve simultaneously. I will be fine with 1000 at the beginning. Is it possible? How many concurrently executions my aws account (if not anymore free tier) could manage of a single function and overall through all functions by default? I will use Europe (Milano) region. With my account, right now, I can performe 10 concurrent executions of my function. I attached my concurrency data in the image:![Enter image description here](/media/postImages/original/IMS9LLlqoWQcqO9cDBFWBcOw) And my code:; import AWS from 'aws-sdk'; AWS.config.update({ accessKeyId: 'idKey', secretAccessKey: 'SecretKey', region: 'eu-west-3', }); const lambda = new AWS.Lambda(); var Utente = {feature: "feature"}; const params = { FunctionName: 'Lambda', Payload: JSON.stringify(Utente) }; ˙ lambda.updateFunctionConfiguration({ FunctionName: 'Lambda', Environment: { Variables: {} } }).promise(); function Invokation(params){ lambda.invoke(params, (error, data) => { if (error) { console.log(error) } else { console.log("OK") } }) }; for (let index = 0; index < 20; index++) { console.log(index); Invokation(params); }
1
answers
0
votes
29
views
asked 9 days ago

WebsocketApi Lambda and connect ECONNREFUSED

Hello, I've been setting up Websocket API with Lambda and I received following error: ``` <message-id> INFO Error: connect ECONNREFUSED <ip> at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1300:16) { errno: -111, code: 'ECONNREFUSED', syscall: 'connect', address: <ip>, port: 80, '$metadata': { attempts: 1, totalRetryDelay: 0 } ``` Env is a Node18 and Postman (ws) as a client. Lambda's code: ``` import { ApiGatewayManagementApiClient, DeleteConnectionCommand,PostToConnectionCommand } from "@aws-sdk/client-apigatewaymanagementapi"; const api = new ApiGatewayManagementApiClient({endpoint: 'wss://<id>.execute-api.<region>.amazonaws.com/production', region: 'eu-central-1' }) export const handler = async (event) => { console.log(event); const {routeKey, connectionId} = event?.requestContext let msg; console.log(`Request key is ${routeKey} and connectionID is ${connectionId}`) switch(routeKey){ case '$connect': msg = 'connected My friend'; break; case '$disconnect': msg = 'disconnected my friend'; break; case 'message': try{ await replyToMessage(connectionId, 'RAMP PAM PAM') }catch(e){ console.log('EXEPTION ALARM') console.log(e) } break; default: console.log('something bad happened', routeKey); break; } // TODO implement const response = { statusCode: 200 }; return response; }; const replyToMessage = (ConnectionId, message) =>{ const data = {message}; const cmd = new PostToConnectionCommand({ ConnectionId, Data: Buffer.from(JSON.stringify(data)) }) const result = api.send(cmd); console.log(result) return result; } ``` Lambda's policy ``` { "Version": "2012-10-17", "Statement": [ { "Sid": "VisualEditor0", "Effect": "Allow", "Action": "execute-api:*", "Resource": "arn:aws:execute-api:<region><id>:<api-id>/production/*" } ] } ``` Thank you in advance, Arczik!
1
answers
0
votes
24
views
Arczik
asked 10 days ago
2
answers
0
votes
25
views
asked 11 days ago

AWS Parameters and Secrets Lambda Extension does not work with parameter ARN's

The [AWS documentation](https://docs.aws.amazon.com/systems-manager/latest/userguide/ps-integration-lambda-extensions.html#sample-commands-ps) for the Parameters and Secrets Lambda Extension states: ``` To make a call using the Amazon Resource Name (ARN) for a parameter, make an HTTP GET call similar to the following. GET http://localhost:port/systemsmanager/parameters/get?name=arn:aws:ssm:us-east-1:123456789012:parameter/MyParameter ``` however these requests return a 400 stating the parameter name is invalid. Here's a quick example to demonstrate the successful request using the parameter name, and the failed request using the parameter ARN: ```py import json import os from botocore.vendored import requests def lambda_handler(event, context): name_url = 'http://localhost:2773/systemsmanager/parameters/get?name=test-param' arn_url = 'http://localhost:2773/systemsmanager/parameters/get?name=arn:aws:ssm:us-east-2:{ACCOUNT_ID}:parameter/test-param' headers = {'X-Aws-Parameters-Secrets-Token': os.environ['AWS_SESSION_TOKEN']} name_resp = requests.get(name_url, headers=headers) print(f'NAME RESPONSE: {name_resp.status_code} > {name_resp.text}') arn_resp = requests.get(arn_url, headers=headers) print(f'ARN RESPONSE: {arn_resp.status_code} > {arn_resp.text}') ``` and the output: ``` NAME RESPONSE: 200 > {"Parameter":{"ARN":"arn:aws:ssm:us-east-2:{ACCOUNT_ID}:parameter/test-param","DataType":"text","LastModifiedDate":"2022-11-26T02:25:14.669Z","Name":"test-param","Selector":null,"SourceResult":null,"Type":"SecureString","Value":"AQICAH....=","Version":2},"ResultMetadata":{}} ARN RESPONSE: 400 > an unexpected error occurred while executing request [AWS Parameters and Secrets Lambda Extension] 2022/11/26 18:09:36 ERROR GetParameter request encountered an error: operation error SSM: GetParameter, https response error StatusCode: 400, RequestID: {REQUEST_ID}, api error ValidationException: Invalid parameter name. Please use correct syntax for referencing a version/label <name>:<version/label> ``` The docs also state: ``` When using GET calls, parameter values must be encoded for HTTP to preserve special characters. ``` however the error still occurs whether the ARN colons and/or slash are URL-encoded or not like so: ``` http://localhost:2773/systemsmanager/parameters/get?name=arn%3Aaws%3Assm%3Aus-east-2%3A{ACCOUNT_ID}%3Aparameter/test-param http://localhost:2773/systemsmanager/parameters/get?name=arn%3Aaws%3Assm%3Aus-east-2%3A{ACCOUNT_ID}%3Aparameter%2Ftest-param ``` Am I missing something here or is the documentation incorrect in that an ARN can be used for these requests?
0
answers
0
votes
63
views
andy
asked 12 days ago