-
Notifications
You must be signed in to change notification settings - Fork 475
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IOutputCache does not work with Lambda runtime #1702
Comments
@tvytrykush Good morning. I do not think you would be able to test the Have you tried testing CCing @normj for any additional inputs. Thanks, |
Hello @ashishdhingra, that's the point I wanted to emphasize here. Running same app via Kestrel works just fine and correct cache value is being stored and returned in subsequent requests. The problem only arises when running via LambdaEntryPoint and corresponding handler. And regarding your second point - I've also tried running in live AWS Lambda, but the behavior is completely the same - invalid cache value being stored. |
@tvytrykush Good morning. Could you please describe your live AWS Lambda setup, including ElastiCache Redis cluster? I'm assuming there might be some connectivity/permissions issue that you might want to troubleshoot. Thanks, |
Hi @ashishdhingra, I'm pretty sure the connectivity is fine, because lambda can connect to redis and it does write something to cache, but not what is expected. But if of any interest here's the config. and SAM for Lambda: # This AWS SAM template has been generated from your function's configuration. If
# your function has one or more triggers, note that the AWS resources associated
# with these triggers aren't fully specified in this template and include
# placeholder values. Open this template in AWS Application Composer or your
# favorite IDE and modify it to specify a serverless application with other AWS
# resources.
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: An AWS Serverless Application Model template describing your function.
Resources:
mylambda:
Type: AWS::Serverless::Function
Properties:
CodeUri: .
Description: ''
MemorySize: 512
Timeout: 100
Architectures:
- x86_64
EphemeralStorage:
Size: 512
Environment:
Variables:
ASPNETCORE_ENVIRONMENT: Nonprod
EventInvokeConfig:
MaximumEventAgeInSeconds: 21600
MaximumRetryAttempts: 2
ImageUri: >-
<edited>:amd64_latest
PackageType: Image
Policies:
- Statement:
- Sid: AWSLambdaVPCAccessExecutionPermissions
Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
- ec2:CreateNetworkInterface
- ec2:DescribeNetworkInterfaces
- ec2:DescribeSubnets
- ec2:DeleteNetworkInterface
- ec2:AssignPrivateIpAddresses
- ec2:UnassignPrivateIpAddresses
Resource: '*'
- Sid: BasePermissions
Effect: Allow
Action:
- secretsmanager:*
- cloudformation:CreateChangeSet
- cloudformation:DescribeChangeSet
- cloudformation:DescribeStackResource
- cloudformation:DescribeStacks
- cloudformation:ExecuteChangeSet
- docdb-elastic:GetCluster
- docdb-elastic:ListClusters
- ec2:DescribeSecurityGroups
- ec2:DescribeSubnets
- ec2:DescribeVpcs
- kms:DescribeKey
- kms:ListAliases
- kms:ListKeys
- lambda:ListFunctions
- rds:DescribeDBClusters
- rds:DescribeDBInstances
- redshift:DescribeClusters
- redshift-serverless:ListWorkgroups
- redshift-serverless:GetNamespace
- tag:GetResources
Resource: '*'
- Sid: LambdaPermissions
Effect: Allow
Action:
- lambda:AddPermission
- lambda:CreateFunction
- lambda:GetFunction
- lambda:InvokeFunction
- lambda:UpdateFunctionConfiguration
Resource: arn:aws:lambda:*:*:function:SecretsManager*
- Sid: SARPermissions
Effect: Allow
Action:
- serverlessrepo:CreateCloudFormationChangeSet
- serverlessrepo:GetApplication
Resource: arn:aws:serverlessrepo:*:*:applications/SecretsManager*
- Sid: S3Permissions
Effect: Allow
Action:
- s3:GetObject
Resource: '*'
- Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource: '*'
- Sid: ElastiCacheManagementActions
Effect: Allow
Action:
- elasticache:*
Resource: '*'
- Sid: CreateServiceLinkedRole
Effect: Allow
Action:
- iam:CreateServiceLinkedRole
Resource: >-
arn:aws:iam::*:role/aws-service-role/elasticache.amazonaws.com/AWSServiceRoleForElastiCache
Condition:
StringLike:
iam:AWSServiceName: elasticache.amazonaws.com
- Sid: CreateVPCEndpoints
Effect: Allow
Action:
- ec2:CreateVpcEndpoint
Resource: arn:aws:ec2:*:*:vpc-endpoint/*
Condition:
StringLike:
ec2:VpceServiceName: com.amazonaws.elasticache.serverless.*
- Sid: AllowAccessToElastiCacheTaggedVpcEndpoints
Effect: Allow
Action:
- ec2:CreateVpcEndpoint
NotResource: arn:aws:ec2:*:*:vpc-endpoint/*
- Sid: TagVPCEndpointsOnCreation
Effect: Allow
Action:
- ec2:CreateTags
Resource: arn:aws:ec2:*:*:vpc-endpoint/*
Condition:
StringEquals:
ec2:CreateAction: CreateVpcEndpoint
aws:RequestTag/AmazonElastiCacheManaged: 'true'
- Sid: AllowAccessToEc2
Effect: Allow
Action:
- ec2:DescribeVpcs
- ec2:DescribeSubnets
- ec2:DescribeSecurityGroups
Resource: '*'
- Sid: AllowAccessToKMS
Effect: Allow
Action:
- kms:DescribeKey
- kms:ListAliases
- kms:ListKeys
Resource: '*'
- Sid: AllowAccessToCloudWatch
Effect: Allow
Action:
- cloudwatch:GetMetricStatistics
- cloudwatch:GetMetricData
Resource: '*'
- Sid: AllowAccessToAutoScaling
Effect: Allow
Action:
- application-autoscaling:DescribeScalableTargets
- application-autoscaling:DescribeScheduledActions
- application-autoscaling:DescribeScalingPolicies
- application-autoscaling:DescribeScalingActivities
Resource: '*'
- Sid: DescribeLogGroups
Effect: Allow
Action:
- logs:DescribeLogGroups
Resource: '*'
- Sid: ListLogDeliveryStreams
Effect: Allow
Action:
- firehose:ListDeliveryStreams
Resource: '*'
- Sid: DescribeS3Buckets
Effect: Allow
Action:
- s3:ListAllMyBuckets
Resource: '*'
- Sid: AllowAccessToOutposts
Effect: Allow
Action:
- outposts:ListOutposts
Resource: '*'
- Sid: AllowAccessToSNS
Effect: Allow
Action:
- sns:ListTopics
Resource: '*'
ReservedConcurrentExecutions: 10
SnapStart:
ApplyOn: None
VpcConfig:
SecurityGroupIds:
- sg-<edited>
SubnetIds:
- subnet-<edited>
- subnet-<edited>
- subnet-<edited>
Ipv6AllowedForDualStack: false
Events:
Api1:
Type: Api
Properties:
Path: /{proxy+}
Method: ANY
|
Since you called out you have a public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddOutputCache(options =>
options.AddBasePolicy(builder =>
builder.AddPolicy<OutputCacheRedisPolicy>().Cache(),
true))
.AddStackExchangeRedisOutputCache(opts =>
{
opts.Configuration = "localhost:6379";
opts.InstanceName = "lambda";
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseHttpsRedirection();
app.UseOutputCache();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapGet("/", async context =>
{
await context.Response.WriteAsync($"{DateTime.Now}: Welcome to running ASP.NET Core on AWS Lambda");
});
});
}
} and using your
|
@normj Actually I've just tried root path as you're using, but it's completely the same, you get valid response on the first request and invalid on all subsequent requests. It's same as using (for reference) the
and when I execute again:
Values stored in cache:
Don't you ming checking what's stored in the cache value? |
Describe the bug
When using IOutputCache feature of asp.net core the cached value is not populated from the response body and is empty
Expected Behavior
Response's cache value is properly cached from response body alongside the key(that is cached properly)
Current Behavior
Because empty value is being cached with valid key - on subsequent requests using same path the response body is going to be empty.
Reproduction Steps
app.UseOutputCache();
before app.UseEndpoints in ConfigurePossible Solution
No response
Additional Information/Context
No response
AWS .NET SDK and/or Package version used
Amazon.Lambda.AspNetCoreServer v9.0.0
Microsoft.AspNetCore.OutputCaching.StackExchangeRedis v8.0.0
Targeted .NET Platform
.NET 8
Operating System and version
MacOS Sonoma 14.2.1
The text was updated successfully, but these errors were encountered: