I am tried enabling the snapstart for my lambda function which just uses a simple java AWS SDK to connect to just a put a message to the queue. Without the snapstart the code works fine, however when its enabled, I get this error
Error while submitting the message with exception :Unable to load AWS credentials from any provider in the chain
I have attached the full access policy for the SQS and its working fine without the snapstart.
final Map<String, MessageAttributeValue> messageAttributes = new HashMap<>();
messageAttributes.put("testID", new MessageAttributeValue().withStringValue("id123").withDataType("String"));
final AmazonSQS sqs = AmazonSQSClientBuilder.standard().withRegion(Regions.EU_WEST_1).build();
final SendMessageRequest sendMessageStandardQueue = new SendMessageRequest().withQueueUrl("https://sqs.eu-west-1.amazonaws.com/111111/my-queue")
.withMessageBody("Test message from lambda")
.withMessageAttributes(messageAttributes);
sqs.sendMessage(sendMessageStandardQueue);
This code works fine without enabling snapstart on the lambda function. After enabling snapstart, I just added the following on the code.
@Override
public void beforeCheckpoint(org.crac.Context<? extends Resource> context) throws Exception {
System.out.println("Before Checkpoint");
}
@Override
public void afterRestore(org.crac.Context<? extends Resource> context) throws Exception {
System.out.println("After Restore");
}
Would you please help me to understand why exactly is it unable to load the credentials. ?
3
Answers
If you are relying on the AWS SDK’s Environment Credentials Provider, then a rehydrated SnapStart Lambda Function will not find the AWS credentials. Per Using SnapStart with the AWS SDKs:
So, I think this means:
If that isn’t the issue, then try to determine if your Lambda function relies on state that is not resilient to snapshot and restore operations. Consider using the AWS Lambda SnapStart Bug Scanner to investigate further.
In particular, the compatibility considerations include:
Also, a few restrictions at launch per the blog post:
For Snapstart environment, we will be using Container Credentials for SDK; for a normal Lambda environment, we can use Environment Credentials for SDK. One way to figure out which environment we are in is to check the container URI:
How to place it working?
Using AWS SDK v2: