Returning custom status code from AWS Proxy lambda function based on certain condition, like 204, 404, but I get always 200 code as a response
We are using below set up for AWS Lambda function. 1 Lambda type - Proxy lambda 2 Handler - org.springframework.cloud.function.adapter.aws.FunctionInvoker 3 Using spring cloud functions for implementing core logic 4 Tried returning below objects as a return type by setting explicitly custom http status code APIGatewayProxyResponseEvent Message> I always get 200 irrespective whatever I set in the response object.
do you know?
how many words do you know
See also questions close to this topic
-
Upload file from html when block public access is true
I am using
django-s3direct
to file uploadhttps://github.com/bradleyg/django-s3direct
Using IAM role setting because I upload the file from the server on ECS container.
Now I set the
blockPublicAccess
ofS3
false.When uploading images from html, there comes error.
https://s3.ap-northeast-1.amazonaws.com/static-resource-v/images/c64d6e593de44aa5b10dcf1766582547/_origin.jpg?uploads (403 (Forbidden) ) initiate error: static-resource-v/line-assets/images/c64d6e593de44aa5b10dcf1766582547/_origin.jpg AWS Code: AccessDenied, Message:Access Deniedstatus:403
OK, it is understandable.
Browser try to access the for initiation.
However there is any way to upload file from browser when blockPublicAccess is true??
-
Linux on Lightsail instance is asking for a password and it's not working
I'm trying to restart
mariaDB
on Ubuntu but it's not letting me.I enter:
systemctl restart mariadb
and get:
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units === Authentication is required to restart 'mariadb.service'. Authenticating as: Ubuntu (ubuntu) Password: polkit-agent-helper-1: pam_authenticate failed: Authentication failure ==== AUTHENTICATION FAILED ===
I have the same password for all functions so I do not understand why it is not working. What can I do?
-
AWS Pinpoint sendMessages() Addresses param field error
I'm having trouble replicating the format of the params object's Addresses format in a way where I can easily add to the object.
If I use this as the params with
destinationNumber[0]
anddestinationNumber[1]
in the format of 1 + 9 digit number ie13334535667
then it sends the message to both numbers no problem.const params = { ApplicationId: applicationId, MessageRequest: { Addresses: { [destinationNumber[0]]: { ChannelType: 'SMS' }, [destinationNumber[1]]: { ChannelType: 'SMS' } }, MessageConfiguration: { SMSMessage: { Body: message, Keyword: registeredKeyword, MessageType: messageType, OriginationNumber: originationNumber } } } };
I'm trying to replicate this format for
Addresses
, but I'm gettingUnexpected key '13334535667' found in params.MessageRequest.Addresses['0']
. The format my console output shows for Addresses is[ { '12345678910': { ChannelType: 'SMS' } }, { '12345678911': { ChannelType: 'SMS' } } ]
I'm using a map to call this
function createPhoneMessagingObject(phoneNumber: string) { return { [phoneNumber]: { ChannelType: 'SMS' } }; }
I tried wrapping key in array like in phone object, but per the output, the brackets goes away so maybe there's an easier/more correct way of doing this. I appreciate any help!
-
AWS Lambda Function Direct Post Payload Always Null
I'm trying to use Lambda Functions (C#) with the Function URL for direct access. In postman I'm sending a basic json body that matches the class properties in my input parameter (PostBody). When I execute the POST request, the values are always null tho. Is the input supposed to be something else besides the expected class?
public string FunctionHandler(PostBody input, ILambdaContext context) { LambdaLogger.Log(JsonSerializer.Serialize(input)); return "Reached Here"; }
-
Is there a way to filter with AWS SNS filter policies from the message body to SQS queues?
I have a general question about SNS filter policies. I know that the filter policies filter based on the Message Attributes. If we wanted to filter based on the body, is there a work around to do so?
The SNS topic will be delivering different types of data to SQS queues based on the filter policies.
-
How to import existing lambda from arn and add SQS as event source? Amplify
I'm trying to create an SNS topic that an SQS queue subscribes to which acts as an event source for a Lambda function. I'm trying to do this with the amplify cdk integration. However, there seems to be some problem when trying to reference the function which results in a permission problem.
CREATE_FAILED fetchMetadataSqsEventSourcesqsqueue2144E8FE AWS::Lambda::EventSourceMapping Fri May 06 2022 17:20:15 GMT+0200 (Central European Summer Time) Resource handler returned message: "Invalid request provided: The provided execution role does not have permissions to call ReceiveMessage on SQS (Service: Lambda, Status Code: 400, Request ID: 2b3147b0-8f59-4c35-8f0f-b7c29a45f139, Extended Request ID: null)" (RequestToken: c03cf5fb-283b-6d83-93c0-f7ee018338cd, HandlerErrorCode: InvalidRequest)
Here's my code
import * as AmplifyHelpers from "@aws-amplify/cli-extensibility-helper" import * as iam from "@aws-cdk/aws-iam" import * as lambda from "@aws-cdk/aws-lambda" import { SqsEventSource } from "@aws-cdk/aws-lambda-event-sources" import * as sns from "@aws-cdk/aws-sns" import * as subs from "@aws-cdk/aws-sns-subscriptions" import * as sqs from "@aws-cdk/aws-sqs" import * as cdk from "@aws-cdk/core" import { Duration } from "@aws-cdk/core" import { AmplifyDependentResourcesAttributes } from "../../types/amplify-dependent-resources-ref" export class cdkStack extends cdk.Stack { constructor( scope: cdk.Construct, id: string, props?: cdk.StackProps, amplifyResourceProps?: AmplifyHelpers.AmplifyResourceProps ) { super(scope, id, props) /* Do not remove - Amplify CLI automatically injects the current deployment environment in this input parameter */ new cdk.CfnParameter(this, "env", { type: "String", description: "Current Amplify CLI env name", }) /* AWS CDK code goes here - learn more: https://docs.aws.amazon.com/cdk/latest/guide/home.html */ // Example 1: Set up an SQS queue with an SNS topic const amplifyProjectInfo = AmplifyHelpers.getProjectInfo() const sqsQueueResourceNamePrefix = `sqs-queue-${amplifyProjectInfo.projectName}` const queue = new sqs.Queue(this, "sqs-queue", { queueName: `${sqsQueueResourceNamePrefix}-${cdk.Fn.ref("env")}`, visibilityTimeout: Duration.seconds(30), // default, receiveMessageWaitTime: Duration.seconds(20), // default }) // 👇create sns topic const snsTopicResourceNamePrefix = `sns-topic-${amplifyProjectInfo.projectName}` const topic = new sns.Topic(this, "sns-topic", { topicName: `${snsTopicResourceNamePrefix}-${cdk.Fn.ref("env")}`, }) // 👇 subscribe queue to topic topic.addSubscription(new subs.SqsSubscription(queue)) new cdk.CfnOutput(this, "snsTopicArn", { value: topic.topicArn, description: "The arn of the SNS topic", }) const dependencies: AmplifyDependentResourcesAttributes = AmplifyHelpers.addResourceDependency( this, amplifyResourceProps.category, amplifyResourceProps.resourceName, [ { category: "function", // api, auth, storage, function, etc. resourceName: "fetchMetadata", // find the resource at "amplify/backend/<category>/<resourceName>" } /* add more dependencies as needed */, ] ) const fetchMetadataFnArn = cdk.Fn.ref( dependencies.function.fetchMetadata.Arn ) const lambdaRole = new iam.Role(this, "Role", { assumedBy: new iam.ServicePrincipal("lambda.amazonaws.com"), description: "Example role...", }) queue.grantConsumeMessages(lambdaRole) let fn = lambda.Function.fromFunctionAttributes(this, "fetchMetadata", { role: lambdaRole, functionArn: fetchMetadataFnArn, }) queue.grantConsumeMessages(fn) const eventSource = new SqsEventSource(queue) fn.addEventSource(eventSource) } }
Here's a snippet of the generated CloudFormation code, it seems like there might be an issue with the arn?
-
How to pass a parameter to a Spring Cloud Function?
I'm following the Spring Cloud Function tutorial.
In the example, they are calling the
revert
bean with this command:curl localhost:8080/reverseString -H "Content-Type: text/plain" -d "abc"
I like to call the endpoint from a browser/postman as a GET request.
So I was looking to orchestrate a URL with a query parameter, that may look like
localhost:8080/reverseString?input=abc
But:
- It is not clear to me what should be the name of the parameter?
- Seems like no matter what method name we put, they all get
HTTP 200
response, with no response body.reverseStringggg
,reve
...
-
How to get Context for logging when using APIGatewayProxyRequestEvent in aws-lambda
My project is written in spring-cloud-function and deployed in aws-lambda. I have a requirement wherein I am supposed to log the events.
A little search told me to use
com.amazonaws.services.lambda.runtime.Context
for logging by doing this:context.getLogger().log("log event here");
I have a spring cloud function which receives APIGatewayProxyRequestEvent as the input and APIGatewayProxyResponseEvent as the output parameter
I searched again and found to get the context, this can be wrapped with
org.springframework.messaging.Message
so I wrote the function like this:
public Function<Message<APIGatewayProxyRequestEvent>, APIGatewayProxyResponseEvent> saveEmployee(){ return request -> { Context context = request.getHeaders().get("aws-context", Context.class); context.getLogger().log("employee save request---: " + request); //do something
However the context evaluates to null and I get NullPointerException
Can someone point to what might be going wrong? or how to fetch context?
Thanks in advance
-
POST search api execution throwing Execution failed due to configuration error: Status code must be between 100 and 599
I have spring-cloud-function project deployed in aws-lambda hit by api-gateway.
I have a search api implemented using POST method with the following request body
{ "criteria": { "name": "employeeId", "value": 22 } }
The name of the function has been configured in aws-lambda environment variable configuation using the key as: spring_cloud_function_definition and value as getEmployeeById
Also the handler has been configured with the following value: org.springframework.cloud.function.adapter.aws.FunctionInvoker
For testing purposes I have kept the code of my function to be very simple for now. I actually removed a lot of code due to the same exception as I am going to share below. So now the code looks something like this:
@Bean public Function<Message<APIGatewayProxyRequestEvent>, APIGatewayProxyResponseEvent> getEmployeeById(){ return request -> { try { APIGatewayProxyResponseEvent responseEvent = new APIGatewayProxyResponseEvent(); responseEvent.setBody("test employee"); return responseEvent; } catch(Exception e) { e.printStackTrace(); e.getMessage(); throw new RuntimeException(e.getMessage()); } }; }
However when I hit the api-gateway(configured to call the lambda) with the request body as shown above, I get the following exception:
Endpoint response body before transformations: {"statusCode":null,"headers":null,"multiValueHeaders":null,"body":"test employee","isBase64Encoded":null} Thu Apr 28 10:15:51 UTC 2022 : Execution failed due to configuration error: Status code must be between 100 and 599 Thu Apr 28 10:15:51 UTC 2022 : Method completed with status: 502
Looks like some configuration issue. Any suggestions as to what might be going wrong?
Thanks in advance